1

i send email with PHPMailer, my code is:

$mail = new PHPMailer(true);
$mail->Mailer       = "smtp";
$mail->IsSMTP();  // telling the class to use SMTP
$mail->SMTPDebug    = 0; 
$mail->SMTPSecure = 'tls';
$mail->Host     = "smtp.gmail.com"; // SMTP server
$mail->Username   = "nati323@gmail.com";
$mail->Password   = "****";
$mail->addCustomHeader('Content-Type: text/plain; charset="utf-8"');
$mail->SMTPAuth   = true;       
$mail->Port       = 587;
$mail->From     = $from;
$mail->AddAddress($to);
$mail->Subject  = $subject;
$mail->Body     = $msg;
return $mail->Send();

the $msg variable is a function parameter i use it like this:

function sendMail ($to, $subject, $msg, $from, $add = null)

and i use it like this:

sendMail($_POST['mail'], $text['EMAIL_RECOVER_MSG_SUBJECT'], $text['EMAIL_RECOVER_MSG'], $from)

the variables contain:

$text['EMAIL_RECOVER_MSG_SUBJECT'] = 'Password Recover: From dmworld24.com';
$text['EMAIL_RECOVER_MSG'] = 'You Forget Your Password To Recover it Please Go Into The Next Link:\r\n http://dmworld24.com/login.php?act=rec&token={TOKEN}&mail={MAIL} \r\n If You Didnt Ask For Password Recovering Just Ignore This Message';
$from = 'System@dmworld24.com';

now i try to add line break to message for example:

You Forget Your Password To Recover it Please Go Into The Next Link:\r\n http://dmworld24.com/login.php?act=rec&token=7054343021*****353214&mail=nati323@gmail.com \r\n If You Didnt Ask For Password Recovering Just Ignore This Message

and what i get in the mail is the same, the \r\n shows as chars and there is not line breaks, what i did wrong?

another problem that i have, that the form method dosent work, i send email for try to nati323@gmail.com , and i connect to smtp server with nati323@gmail.com acount, and i always get the message from my self, and the Form that i defined dosent show....

Kaki Baleven
  • 355
  • 3
  • 7
  • 19

2 Answers2

2

You're using single quotes in your message. That will take everything contained in it literally, which is why you're getting the literal string \r\n.

Replace the single quotes with double quotes to get the new line properly output.

I.e.

$text['EMAIL_RECOVER_MSG'] = "You Forget Your Password To Recover it Please Go Into The Next Link:\r\n http://dmworld24.com/login.php?act=rec&token={TOKEN}&mail={MAIL} \r\n If You Didnt Ask For Password Recovering Just Ignore This Message";`
Jonnix
  • 4,121
  • 1
  • 30
  • 31
  • For your second question you should read http://stackoverflow.com/questions/5431631/when-using-gmail-for-smtp-can-you-set-a-different-from-address – Jonnix May 18 '15 at 22:49
  • i read it just now, but they require that i insert an SMTP address, and i dont have one like this right now, i guess that there is no other way... – Kaki Baleven May 18 '15 at 22:52
0

Call the PHP function nl2br() to convert newlines to HTML line breaks. And then, setup PHPMailer to sent email as an html using $mail->IsHTML(TRUE);

Rajesh
  • 3,743
  • 1
  • 24
  • 31