用PHP解析电子邮件中的HTML

用PHP解析电子邮件中的HTML,php,html,forms,email,Php,Html,Forms,Email,我有一个表单,我正在使用它来简单地捕获用户的姓名和电子邮件。当用户提交表单时,将向包含链接的指定收件人发送一封电子邮件 我让这一切工作,但我意识到我需要添加一个html页脚的电子邮件,这是最初被读为纯文本 在做了一些挖掘之后,我现在尝试将页脚设置为html,但电子邮件不再发送。我不是php开发人员 我的问题是,我是错过了什么,还是我刚好错过了什么 <?php // configure $from = 'Ether Solutions Sales <email@domain.co.u

我有一个表单,我正在使用它来简单地捕获用户的姓名和电子邮件。当用户提交表单时,将向包含链接的指定收件人发送一封电子邮件

我让这一切工作,但我意识到我需要添加一个html页脚的电子邮件,这是最初被读为纯文本

在做了一些挖掘之后,我现在尝试将页脚设置为html,但电子邮件不再发送。我不是php开发人员

我的问题是,我是错过了什么,还是我刚好错过了什么

<?php

// configure
$from = 'Ether Solutions Sales <email@domain.co.uk>';
$sendTo = $_POST['remail'];
$subject = "test email";
$name = $_POST['name'];
$okMessage = 'your message has been sent successfully, please ask the recipient to check their inbox';
$errorMessage = 'There was an error while submitting the form. Please try again later';

// 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";


// Create email headers

$headers .= 'From: '.$from."\r\n".'Reply-To: '.$from."\r\n" . 'X-Mailer: PHP/' . phpversion();

// Compose a simple HTML email message

$message = '<html><body>';

$message .= '<p style="margin-bottom:30px;">regards dave</p>';

$message .= '<a href="http://www.domain.co.uk" title="link to domain website">www.domain.co.uk</a>';
$message .= '<p style="font-color:blue;">Office Tel: 0844 000 000</p>';
$message .= '<p style="font-color:blue;">Mobile: 0000 000 0000</p>';
$message .= '<p style="font-color:blue;">Technical Support: 0845 000 0000</p>
';
$message .= '<p style="font-color:blue; font-weight:bold;">Some tagline here</p>
';
$message .= '<img src="imageurl/test.png" alt="sample alt tag"/>';

$message .= '</body></html>';


// let's do the sending

try
{   
    $emailText = "{$name} you have been sent an electronic document to be signed.\nTo view your document please click the following link URL: /www.domain.com";


    mail($sendTo, $subject, $emailText, $message, $headers, "From: " . $from);

    $responseArray = array('type' => 'success', 'message' => $okMessage);
}
catch (\Exception $e)
{
    $responseArray = array('type' => 'danger', 'message' => $errorMessage);
}

if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
    $encoded = json_encode($responseArray);

    header('Content-Type: application/json');

    echo $encoded;
}
else {
    echo $responseArray['message'];
}

您对
邮件()的调用错误。您设置的参数不正确

看一看报纸

来自php手册

mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )
您的代码
邮件($sendTo,$subject,$emailText,$message,$headers,“From:$From)
邮件
用作
$附加头
,这是错误的


您必须将您的
$message
$emailText

合并。我测试了您的代码并得到以下警告: [18-Aug-2017 12:44:15 Africa/Nairobi]PHP警告:mail()最多需要5个参数,6个参数在第47行的/home/ruemerc/public_html/lab/email2/mail.PHP中给出

我建议您使用这里的PHPMailer库

。它甚至可以让你发送大量电子邮件(我认为这对你来说是一个额外的优势)。
享受编码乐趣

我想您需要检查
邮件
函数的参数。您好,最好使用包装邮件函数的PHPMailer库。看这个:谢谢兄弟,我按照建议把两者合并了,但是现在我遇到了一个问题。是的,电子邮件是以html格式发送的,这很好。但是最初$emailText还在解析字符串开头的name变量。当$message与html一起使用时,这仍然可以实现吗?谢谢Mwangi,我已经合并了$message和$emailText,html电子邮件现在发送,尽管我现在必须弄清楚如何解析客户端$name,因为$message与htmlOk一起使用。您的意思是将$name包含在$message中吗?$message=''$消息。='

表示对“$name”的关注。

”$message.='“title=”链接到域网站“>www.domain.co.uk';$message.='

办公室电话:084400000;$message.=”

手机:0000 000 000

”;$message.='

此处的一些标语

”;$message.=';$message.='''';即关于“$name.”最初我将$emailText变量包含在双引号中,因为它实际上只包含文本,允许我通过{$name}添加$name变量方法。现在我已将这两个变量合并到包含html的$message变量中,因此我使用单引号。我想在邮件的开头添加$name变量,以包含收件人姓名。在答复之前,我尝试过。$name。它不起作用。我现在使用$name进行工作。后跟html字符串:)谢谢感谢你为我指明了正确的方向,感谢你今天的耐心:)