SMTP邮件服务器发送邮件不起作用

时间:2013-12-10 06:50:39

标签: php email smtp

我正尝试从gmail

通过smtp发送邮件

我的PHP代码是

<?php
$body             = 'test body';
$to = "test_useremail@example.org";
$from = 'mytestmail@gmail.com';
$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   = "mytestmail@gmail.com"; // 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.

我不知道有什么问题?

4 个答案:

答案 0 :(得分:0)

你可以使用它为我工作的代码

  <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 = shlomo@zend.com</center><br>
  </body>


  <?php
  // Using the ini_set()
  ini_set("SMTP", "mail.zend.com");
  ini_set("sendmail_from", "shlomo@zend.com");
  //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 = YourMail@address.com";

// Send
$headers = "From: shlomo@zend.com";

mail('shlomo@zend.com', 'My Subject', $message, $headers);

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

只需更改您的凭据即可 实际链接http://kb.zend.com/smtp-mail-the-php-mail-function-for-iseries/#.Uqa9NY1Mhno

答案 1 :(得分:0)

$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='';

答案 2 :(得分:0)

  

SMTP - &gt;错误:无法连接到服务器:权限被拒绝(13)

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

答案 3 :(得分:0)

您是在localhost中工作还是托管在某个服务器上?

默认情况下,从localhost我们无法发送邮件,因为SMTP不可用。