Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am doing some testing prior to working on some production code and need to figure out how to do an auto e-mail.

The below script runs fine and the result of the send method returns 1, as if it sends. However, nothing ever makes it to the recipient.

           require_once '/home/absolut2/lib/swift_required.php';

    //Create the Transport
    $transport = Swift_SmtpTransport::newInstance('mail.mysite.com', 25)
      ->setUsername('myuser')
      ->setPassword('password')
              ;

    /*
    You could alternatively use a different transport such as Sendmail or Mail:

    //Sendmail
    $transport = Swift_SendmailTransport::newInstance('/usr/sbin/sendmail -bs');

    //Mail
    $transport = Swift_MailTransport::newInstance();
    */

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

    //Create a message
    $message = Swift_Message::newInstance('Subject')
      ->setFrom(array('[email protected]' => 'RP'))
      ->setTo(array('[email protected]'))
      ->setBody('Here is the message itself');


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

            echo "Messages sent: " . $result;
share|improve this question
 
Is your mail function working properly ? –  nidhin Jul 29 '11 at 4:09

1 Answer

The code itself seems fine, so I guess something else is wrong. Either check the spam queue of the recipient or maybe just the address was rejected.

Find out if addresses were rejected.

You can do that with this code:

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.