Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
230 views
in Technique[技术] by (71.8m points)

Send HTML Email using PHP - Not working when using [email protected]?

I am using this basic php code to send out a html email.

When i use [email protected] as a to address the script works. However, when i try to use [email protected] the script says:

Parse error: syntax error, unexpected '@' in /home/u925912002/public_html/send_email.php on line 3

My code:

<?php

$to = ‘[email protected]’;

$subject = 'I need to show html'; 

$from ='[email protected]'; 

$body = '<p style=color:red;>This text should be red</p>';

ini_set("sendmail_from", $from);

$headers = "From: " . $from . "
Reply-To: " . $from . "";
  $headers .= "Content-type: text/html
"; 
if (mail($to, $subject, $body, $headers)) {

  echo("<p>Sent</p>");
 } else {
  echo("<p>Error...</p>");
 }

?>

please can someone show me what i'm doing wrong. thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

For your question recently closed: https://stackoverflow.com/questions/34106770/send-email-using-php-from-address-not-working

Try this:

$headers .= "From: Your Name <$from> ";

and you can also add the 5th mail parameter:

mail($to, $subject, $body, $headers, '[email protected]').

Works for me with these headers:

$from = "$name <$email>
";
$to = "$username <$useremail>
";
$headers  = 'MIME-Version: 1.0' . "
";
$headers .= 'Content-type: text/html; charset=utf-8' . "
";
$headers .= "From: $name <$email>
";
$headers .= "Reply-To: $name <$email>
";

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...