Reputation: 297
I use php curl() function to connect from server A to the mail server B to send mail.
$body = "body\n\nmore body\nmore body\n\nmore body\n\n";
$post = [
'sendera' => $sender,
'sender_name' => $sender_name,
'subject' => $subject,
'body' => $body,
'recipient' => $email,
'recipient_name' => $name,
'replyto' => $replyto
];
$ch = curl_init('http://example-mailserver.com');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT ,3);
curl_setopt($ch,CURLOPT_TIMEOUT, 10);
$response = curl_exec($ch);
curl_close($ch);
Mail is successfully sent but there are 2 problems.
Problem N 1
Mail arrive without line breaks, So, all \n are just plain text. Never have had this problem sending mail from the same server. Now when I send with curl(), this problem appears. Mail server have php7 installed. Should this be a php7 or curl() problem?
Problem N 2
Mail arrive without subject line, however $subject variable exists when script runs, I checked this by sending one more simple mail before calling PHPMailer() function.
So, why PHPMailer ignores $subject? I never have had this problem on the server A with php5.
mail('my@email', 'check if subject exists', $subject);
The mail above arrive with $subject variable. But the mail sent right after that with phpmailer does not have subject line.
$mail=new PHPMailer();
$mail->IsMail();
$mail->WordWrap = 0;
$mail->SingleTo = true;
$mail->IsHTML(false);
$mail->CharSet = "utf-8";
$mail->From = $sender;
$mail->FromName = $sender_name;
$mail->Subject = $subject;
$mail->Body = $body;
$mail->AddAddress($recipient,$recipient_name);
$mail->AddReplyTo(#replyt,"No-Reply");
Upvotes: 3
Views: 3464
Reputation: 297
Subject problem
I installed the latest version of phpmailer and not I have Subject.
Line breaks
I had $body in single quotes:
body = 'this is body\r\n\r\nmore body';
I changed this to:
$body = "this is body\r\n\r\nmore body";
And now everything is OK.
Upvotes: 0
Reputation: 133
Problem no. 1 might be due to the line breaks you are using. A \n
is just one of two elements of a full line break, it's a 'newline'. Some mail systems/servers expect a full line break, which is \r\n
, the \r
in this case is a 'carriage return', the second element of a full line break.
Problem no. 2...first off: what's in your $subject
?
Upvotes: 1