2012-07-02 89 views
0

我试图通过PHP发送电子邮件。它给出以下警告。在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 = [email protected] 

配置php.ini后,WAMP重新启动并发出上述警告。在PHP中通过本地主机发送电子邮件还有哪些其他设置?

+0

*其他*设置?修复您*已有*的设置... –

+0

您可以通过命令行连接到端口25上的那台服务器吗?你需要添加一个用户名和密码? – andrewsi

+0

将SMTP更改为'smtp.gmail.com'并将端口更改为'587'会给出警告'Warning:mail()[function.mail]:SMTP服务器响应:530 5.7.0必须首先发出STARTTLS命令。在线1007上的C:\ wamp \ www \ wagafashion \ customerside \ BulkInquiry.php中的ru4sm13726850pbc.66。 – Tiny

回答

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 = '[email protected]'; 
$mail->Password = '[email protected]#'; 

$mail->SetFrom('[email protected]', $name); 
$mail->AddReplyTo('[email protected]','no-reply'); 
$mail->Subject = 'subject'; 
$mail->MsgHTML($body); 

$mail->AddAddress('[email protected]', 'title1'); 
$mail->AddAddress('[email protected]', 'title2'); /* ... */ 

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