我正在尝试使用 Swiftmailer 发送电子邮件,但它似乎没有设置标题?它发送正常,但电子邮件永远不会到达目的地。当我在 CPanel 中查看我的邮件递送报告时,收件人是未知的。所以我尝试回显标题,但每件事都是空白的......
这是我的代码...
echo "submitting email...";
$transport = Swift_SmtpTransport::newInstance('mail.example.com', 25)
->setUsername'username'
->setPassword('password');
$mailer = Swift_Mailer::newInstance($transport);
$attachment = Swift_Attachment::fromPath($_FILES['attachedfile']['tmp_name'])
->setFilename($name.'_'.$email);
$message = Swift_Message::newInstance()
->setSubject('Submission')
->setFrom(array('myemail@email.com' => 'my name'))
->setTo(array('youremail@gmail.com' => 'your name'))
->setBody('Name: ' . $name . '\nEmail: ' . $email . '\nDescription: ' . $descr)
->attach($attachment);
$headers = $message->getHeaders();
foreach ($headers->getAll() as $header) {
printf("%s<br />\n", $header->getFieldName());
}
$failedRecipients = array();
$result = $mailer->send($message, $failedRecipients);
if($result == 0) {
echo "Failed sending email. Please try again later.<br/>";
} else {
echo "Thanks for your submission!<br/>";
}