[英]SMTP Mail Server sending mail not work
我正在嘗試通過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.
我不知道是什么問題?
您可以使用此代碼為我工作
<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
$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->錯誤:無法連接到服務器:權限被拒絕(13)
這表示不允許您的php腳本打開連接。 檢查此服務器的安全設置(SELinux等)
您是在localhost工作還是在某些服務器上托管?
默認情況下,由於SMTP不可用,因此無法從本地主機發送郵件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.