简体   繁体   中英

PHPMailer with mamp pro on localhost

I am developing on a mac and I am using mamp pro with phpmailer to test some php email code. I was able to successfully send and receive emails using my personal gmail. Now I want to see how I would send an email when the email username is not standard ie @coporateemail.com or @mybusiness.com, but I can't seem to figure out how to configure mamp pro and phpmailer to send out the email from localhost using the 'non standard' email like in the examples above. Here is my phpmailer config code

$mail->Host = 'localhost';
$mail->SMTPAuth = true;
$mail->isSMTP(); 
$mail->SMTPDebug = 4;
$mail->Port = 25;
$mail->SMTPSecure = 'ssl';
$mail->isHtml(true);
$mail->setFrom('info@example.com', $name);
$mail->addReplyTo($replyto, 'noreply@example.com');
$mail->addAddress("example@test.com");
$mail->Subject    = $subject;
$mail->msgHtml($html);
$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test

My php version in mamp pro is 5.6.31. In my php.ini file I have

SMTP = localhost
smtp_port = 25

In MAMP Pro my ports are:

Apache-> port: 3005; ssl port: 25(it was 257 by default)

In the Postfix tab of Mamp Pro I have 'Set domain of outgoing emails to: example.com' and the 'use a smart host for routing' option is unchecked.

Finally my phpmailer error output is as follows

2017-10-29 23:00:29 Connection: opening to ssl://localhost:25, timeout=300, options=array()
2017-10-29 23:00:29 Connection failed. Error #2: stream_socket_client(): unable to connect to ssl://localhost:25 (Connection refused)
2017-10-29 23:00:29 SMTP ERROR: Failed to connect to server: Connection refused (61)
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

So to reiterate. I want to send an email out that is not using gmail but I can't seem to be able to configure phpmailer correctly to do so while on localhost. So what am I doing wrong or missing? Thank you!

SMTPSecure = 'ssl' is nearly guaranteed not to work on port 25 - but why on earth do you have apache listening on port 25? That's postfix's job

You're setting SMTPAuth , but then not setting Username or Password - but you don't need auth for localhost delivery, so just turn that off.

If you're relaying through localhost, you don't need encryption (there's no network segment to protect), and it won't work anyway because you won't have a cert that matches the name.

For the most part all you have to do to send through localhost using SMTP with PHPMailer is call isSMTP() , and the defaults for the other properties should work fine.

If you're working on a new project, don't use an obsolete version of PHP - use at least 7.0.

I think you need to take a step back and define exactly what it is you're trying to do - your current config makes very little sense.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM