2015-10-27 93 views
1

我在线创建表单,并且需要发送电子邮件以包含文件中的内容。变量中的电子邮件内容

我的头都设置这样的

@mail($email_to, $email_subject, $email_message, $headers); 

和我的内容在这里

$email_message = file_get_contents('http://www.link.co.uk/wp-content/themes/themename/email-content.php'); 

该文件中包含电子邮件模板,我的问题是,模板在原始格式通过电子邮件发送出去。

这里是我的代码:

$email_message = file_get_contents('http://www.link.co.uk/wp-content/themes/themename/email-content.php'); 


// create email headers 

$headers = 'MIME-Version: 1.0' . "\r\n"; 
$headers = 'Content-type: text/html; charset=iso-8859-1' . "\r\n";         
$headers = 'From: '.$email_from."\r\n". 

'Reply-To: '.$email_from."\r\n" . 

'X-Mailer: PHP/' . phpversion(); 

@mail($email_to, $email_subject, $email_message, $headers); 

回答

1

这里的问题布拉德,是你的头被打破,被覆盖。

$headers = 'MIME-Version: 1.0' . "\r\n"; 
$headers = 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 
$headers = 'From: '.$email_from."\r\n". 

添加连接(点)

$headers = 'MIME-Version: 1.0' . "\r\n"; 
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 
$headers .= 'From: '.$email_from."\r\n". 

串接像链节。如果有人失踪或没有人,东西不会“持有”或被破坏。 ;-)所以只处理最后一行并忽略MIME和HTML声明。

$headers = 'From: '.$email_from."\r\n". ....

这是一个有效的声明,因为它拥有一个有效的From:,它只是电子邮件不是“格式化”,你希望它的方式。

+0

这就是我一直在寻找的!非常感谢你。我是PHP新手,像你这样的人帮助我! –

+0

@BradHouston你非常欢迎Brad,我很高兴能有所帮助,*欢呼声* –

+0

理论上,我每次宣布其内容时都覆盖头部变量?添加连接添加到变量而不是覆盖!完善! –

1

你指定你的电子邮件是在HTML中的$头?

下面是一个例子:

$headers = 'MIME-Version: 1.0' . "\r\n"; 
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 

来源: http://php.net/manual/en/function.mail.php