SMTP邮件服务器发送邮件无法正常工作

问题描述:

我试图通过SMTP从gmailSMTP邮件服务器发送邮件无法正常工作

我的PHP代码发送邮件

<?php 
$body    = 'test body'; 
$to = "[email protected]"; 
$from = '[email protected]'; 
$fName = 'first name'; 
$lName = 'last name'; 
$subject = 'my subject'; 
$mail = new PHPMailer(); 
$mail->IsSMTP(); 
$mail->CharSet = 'UTF-8'; 
    // $body    = eregi_replace("[\]",'',$body); 
$mail->Host  = "smtp.gmail.com"; // SMTP server example 
$mail->SMTPDebug = 2;      // enables SMTP debug information (for testing) 
$mail->SMTPAuth = true;     // enable SMTP authentication 
$mail->Port  = 587;     // set the SMTP port for the GMAIL server 
$mail->Username = "[email protected]"; // SMTP account username example 
$mail->Password = "password"; 
$mail->SetFrom($from, $fName.' '.$lName); 
$mail->Subject = $subject; 
$mail->AddAddress($to, "Support Team"); 
$mail->MsgHTML($body); 

if(!$mail->Send()) { 
    echo "Mailer Error: " . $mail->ErrorInfo; 
exit; 
} 
?> 

它给我这个错误::

SMTP -> ERROR: Failed to connect to server: Permission denied (13) 
SMTP Error: Could not connect to SMTP host. Mailer Error: SMTP Error: Could not connect to SMTP host. 

我不知道什么是问题?

+0

试试'$ mail-> SMTPSecure ='tls';' 您是否使用gmail的正确凭据? –

+0

增加'$ mail-> SMTPSecure ='tls';'但不能正常工作 –

您可以使用此代码,它是为我工作

<HTML> 
    <body> 
    MAIL SETTING for Iseries<br> 
    Define a real name of your mail Server<br> 
    <center> 
    SMTP = mail.zend.com </center> 
    <br> 
    Define a real name of your mail Server<br> 
    <center> 
    smtp_port = 25</center> 
    <br> 
    Define an any address you want<br> 
    <center> 
    sendmail_from = [email protected]</center><br> 
    </body> 


    <?php 
    // Using the ini_set() 
    ini_set("SMTP", "mail.zend.com"); 
    ini_set("sendmail_from", "[email protected]"); 
    //ini_set("smtp_port", "25"); 

// The message 
    $message = "The mail message was sent with the following mail setting:\r\nSMTP = mail.zend.com\r\nsmtp_port = 25\r\nsendmail_from = [email protected]"; 

// Send 
$headers = "From: [email protected]"; 

mail('[email protected]', 'My Subject', $message, $headers); 

echo "Check your email now….<BR>";?> 
</HTML> 

只要改变你的证书 实际链接http://kb.zend.com/smtp-mail-the-php-mail-function-for-iseries/#.Uqa9NY1Mhno

$subject = "This is subject testing1"; 
$mail = new PHPMailer();  
$mail->IsSMTP(); 
$mail->IsHTML(true); // send as HTML  
$mail->SMTPAuth = true;     // enable SMTP authentication 
$mail->SMTPSecure = "ssl";     // sets the prefix to the servier 
$mail->Host  = "smtp.gmail.com";  // sets GMAIL as the SMTP server 
$mail->Port  = 465;     // set the SMTP port 
$mail->From  = ''; 
$mail->FromName = ""; 
$mail->Subject = $subject; 
$mail->Body  = "this is html body";   //HTML Body 
$emailId=''; 

SMTP -> ERROR: Failed to connect to server: Permission denied (13)

这表明你的PHP脚本不允许打开连接。检查此服务器(SELinux等)的安全设置

你在本地主机上工作或托管在某些服务器?

默认情况下,从本地主机我们不能发送邮件,因为SMTP不可用。

+0

我不在'localhost'工作我正在做网站和直播网站 –

+0

OK,检查以下链接;你可以得到一些解决方案;我认为你需要从服务器执行这些命令。 http://gistpages.com/2013/09/14/phpmailer_smtp_error_failed_to_connect_to_server_permission_denied_13_fix http://blog.innovsystems.com/php/smtp-error-failed-connect-server-permission-denied-13 – Satish