簡體   English   中英

Swiftmailer不發送PHP郵件

[英]Swiftmailer not sending mail in php

error_reporting(E_ALL);
require_once 'swift_required.php';

//Create the Transport
$transport = Swift_SmtpTransport::newInstance('mail.your_domain.com', 25)
->setUsername('name@your_domain.com')
->setPassword('your_password')
;

//Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);

//Create a message
$message = Swift_Message::newInstance('PHP Message')
->setFrom(array('name@your_domain.com'))
->setTo(array('name@your_domain.com'))
->setBody('PHP Swift Mailer sent with authentication')
;

//Send the message
$result = $mailer->send($message);



if (!$mailer->send($message, $failures)) {
echo "Failures:";
print_r($failures);
}

這是我用於發送電子郵件的代碼。 但是它不能正常工作。 甚至沒有任何錯誤或失敗消息。 怎么了?

如果SMTP服務器地址有效且可通過提供的憑據訪問,則您的代碼似乎可以正常工作。 也許您的SMTP服務器地址或登錄憑據不正確,或者SMTP服務器未運行? 該代碼使用有效設置正確運行。

另外,也請嘗試在成功時添加一條消息,以使您知道該代碼已發送電子郵件-否則,如果電子郵件在目標位置被垃圾郵件過濾,則您可能不會注意到它實際上是有效的:

if (!$mailer->send($message, $failures)) {
  echo "Failures:";
  print_r($failures);
} else {
    echo 'email sent successfully';
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM