2013-05-09 2 views
0
error_reporting(E_ALL); 
require_once 'swift_required.php'; 

//Create the Transport 
$transport = Swift_SmtpTransport::newInstance('mail.your_domain.com', 25) 
->setUsername('[email protected]_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('[email protected]_domain.com')) 
->setTo(array('[email protected]_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); 
} 

이것은 이메일을 보내는 데 사용 된 코드입니다. 하지만 제대로 작동하지 않습니다. 오류 또는 실패 메시지도 없습니다. 뭐가 잘못 되었 니?Swiftmailer가 PHP로 메일을 보내지 않음

답변

1

제공된 자격 증명으로 SMTP 서버 주소가 유효하고 연결할 수 있으면 코드가 올바르게 작동하는 것 같습니다. SMTP 서버 주소 또는 로그인 자격 증명이 잘못되었거나 SMTP 서버가 실행되지 않았습니까? 올바른 설정으로 코드가 올바르게 실행되었습니다. 또한

이뿐만 아니라 당신이 코드가 이메일을 보낸 것을 알 수 있도록 성공시 메시지를 추가하려고 - 이메일 얻을 그렇지 않으면 당신은 실제로 일하고있어 주목하지 않을 수 있습니다 스팸 필터링 목적지 :

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