0

我正在尝试通过 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 发送电子邮件需要进行哪些其他设置?

4

1 回答 1

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-07T15:51:40.253 回答