php mail on MAMP

后端 未结 6 1952
栀梦
栀梦 2020-12-10 11:23

I need to test some script using PHP\'s mail. I\'d like to be able to finally get this working locally. I am using MAMP. Is there a way to do this without installing any thi

6条回答
  •  渐次进展
    2020-12-10 12:12

    Few months ago I had a similar problem whilst developing on my local machine an application which involved sending automating email notifications. I have lost quite some time installing Sendmail on OSX and eventually I could not get it working right..

    My approach was to use the PEAR Mail as a temporary replacement for php's native mail function. Basically you can define a function called send-mail (see code below) and, once you deploy your app on a server, you can possibly replace the calls to that function with calls to mail().

          "Your agent ",
                  'To' => $recipient,
                  'Subject' => $subject
                );  
    
                $smtp = Mail::factory(
                 'smtp',
                  array ('host' => $host,
                    'auth' => true,
                    'port' => $port,
                    'username' => $username,
                    'password' => $password)
                );  
                $smtp->send($recipient, $headers, $body);
           }
        ?>    
    

提交回复
热议问题