cant send out any email

南楼画角 提交于 2019-12-06 07:12:27
Christian Gollhardt

You need to have a SMTP server running, which accept your emails, which are send via PHP. You need to point to it in php.ini.

Your Configuration points to localhost. I think, there is no E-Mail Server on localhost running? If so, double check, if it accept E-Mails from localhost (PHP).

Here is how to setup a server:

For IIS:

http://geekswithblogs.net/tkokke/archive/2009/05/31/sending-email-from-php-on-windows-using-iis.aspx

Note, that it is configured over IIS6 Console, also if you have the latest one. For Some reason, it can't be configured with the >=IIS7 Console, but still works with the old one, which is also installed.

For Linux:

How to send email from localhost using PHP on Linux

For Login via SMTP to Mail Account

There is also a good E-Mail Class called PHPMailer, which comes in handy, if we are working with SMTP directly on PHP side:

$mail = new PHPMailer;
$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'smtp1.example.com';  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication

$mail->Username = 'user@example.com';                 // SMTP username
$mail->Password = 'secret';                           // SMTP password
$mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587;                                    // TCP port to connect to

$mail->From = 'from@example.com';
$mail->FromName = 'Mailer';
$mail->addAddress('joe@example.net', 'Joe User');     // Add a recipient
$mail->addAddress('ellen@example.com');               // Name is optional

$mail->Subject = 'Here is the subject';
$mail->Body    = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent';
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!