bwoogie
bwoogie

Reputation: 4427

Swiftmailer not setting headers?

I'm trying to send email with Swiftmailer but it doesn't seem to be setting the headers? It sends ok, but the email never gets to its destination. When I look at my Mail Delivery Reports in CPanel the recipient is unknown. So I tried echoing the header and every thing is blank...

heres my code...

    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('[email protected]' => 'my name'))
    ->setTo(array('[email protected]' => '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/>";
}

Upvotes: 0

Views: 1700

Answers (1)

bwoogie
bwoogie

Reputation: 4427

The problem was with the attachment... I did it wrong. i was pointing to a non existent file... oops.

Upvotes: 1

Related Questions