メールの送信に問題があります。メールサーバーとしてpostfixを実行しているubuntuサーバーがあります。webapp は symfony 1.2 に基づいており、メール送信用に Swift 3 があります。すべてが同じサーバー上で実行されています。これは実行しようとしているコードです:
public static function sendMailLocal($mailFrom, $mailto, $subject, $mailBody, $prevError)
{
$mailer = null;
try
{
$connection = new Swift_Connection_SMTP('localhost', '25');
$mailer = new Swift($connection);
// Create the mailer and message objects
$message = new Swift_Message($subject, $mailBody, 'text/html');
// Send
$mailer->send($message, $mailto, $mailFrom);
$mailer->disconnect();
}
catch (Exception $e)
{
if($mailer != null)
$mailer->disconnect();
throw new EmailTransferException ("There was an error while trying to send the email - locally:" . $e->getMessage() . " , first error:" . $prevError);
}
}
これは私が得ているエラーメッセージです:
電子メールの送信中にエラーが発生しました - ローカル:SMTP 接続を開始できませんでした [localhost:25]: fsockopen がエラー番号 111 とエラー文字列 '接続を拒否しました' を返しました。
このコードを使用して迅速にメールを送信できなかったので、ちょっと奇妙です:
//adresses are examples
$to = "john.doe@mail.com";
$sender_email = "someone@mail.com";
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'To: <'.$to.'>' . "\r\n";
$headers .= 'From: John Doe<'.$sender_email.'>' . "\r\n";
// Mail it
$success = mail($to, "test from server", "msg", $headers);
誰でもこれについて何か考えがありますか??
ありがとう!