【问题标题】:Sending an email via localhost in PHP在 PHP 中通过 localhost 发送电子邮件
【发布时间】:2012-07-03 06:15:52
【问题描述】:

我正在尝试通过 PHP 发送电子邮件。它给出以下警告。

Warning: mail() [function.mail]: Failed to connect to mailserver at 
"smtp.ntlworld.com" port 25, verify your "SMTP" and "smtp_port" setting in 
php.ini or use ini_set() in C:\wamp\www\wagafashion\customerside\BulkInquiry.php 
on line 1007

在 php.ini 中,SMTP 已更改如下。

[mail function]
; For Win32 only.
SMTP = smtp.ntlworld.com
smtp_port = 25

; For Win32 only.
sendmail_from = tiny1999@gmail.com

配置 php.ini 后,WAMP 重新启动并给出上述警告。在 PHP 中通过 localhost 发送电子邮件需要进行哪些其他设置?

【问题讨论】:

  • 其他设置?修复您已有的设置...
  • 你能从命令行连接到该服务器的 25 端口吗?需要添加用户名和密码吗?
  • 将 SMTP 更改为 smtp.gmail.com 并将端口更改为 587 会发出此警告 Warning: mail() [function.mail]: SMTP server response: 530 5.7.0 Must issue a STARTTLS command first. ru4sm13726850pbc.66 in C:\wamp\www\wagafashion\customerside\BulkInquiry.php on line 1007
  • @Tiny 你检查你的防火墙的配置了吗? AV安全软件?也许你背后的路由器?

标签: php email smtp


【解决方案1】:

改用 PHPMailer:https://github.com/PHPMailer/PHPMailer

使用方法:

require('./PHPMailer/class.phpmailer.php');
$mail=new PHPMailer();
$mail->CharSet = 'UTF-8';

$body = 'This is the message';

$mail->IsSMTP();
$mail->Host       = 'smtp.gmail.com';

$mail->SMTPSecure = 'tls';
$mail->Port       = 587;
$mail->SMTPDebug  = 1;
$mail->SMTPAuth   = true;

$mail->Username   = 'me.sender@gmail.com';
$mail->Password   = '123!@#';

$mail->SetFrom('me.sender@gmail.com', $name);
$mail->AddReplyTo('no-reply@mycomp.com','no-reply');
$mail->Subject    = 'subject';
$mail->MsgHTML($body);

$mail->AddAddress('abc1@gmail.com', 'title1');
$mail->AddAddress('abc2@gmail.com', 'title2'); /* ... */

$mail->AddAttachment($fileName);
$mail->send();

【讨论】:

    猜你喜欢
    • 2014-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-19
    • 2012-06-29
    • 2010-11-22
    • 2010-10-09
    相关资源
    最近更新 更多