大家好,我有一个非常基本的php问题,关于将表单数据添加到使用phpmailer发送的html / php文件中
我使用gmail帐户SMTP在成功提交表单时发送HTML电子邮件。
在表单提交上,HTML电子邮件已成功发送。
问题/问题:
我无法将输入到各种标题中的表格数据附加到我发送为电子邮件的HTML文件中。
这是PHP调用的代码:用于表单提交。 email-content.php是使用Gmail SMTP成功发送为HTML电子邮件的文件。
<?php
$salutation = $_POST['salutation'] ;
$name = $_POST['name'] ;
//
$dateDOB = $_POST['DOB_Day'] ;
$monthDOB = $_POST['DOB_Month'] ;
$yearDOB = $_POST['DOB_Year'] ;
//
$mobileLandline1 = $_POST['mobileLandline1'] ;
$mobileLandline2 = $_POST['mobileLandline2'] ;
$mobileLandline3 = $_POST['mobileLandline3'] ;
$mobileLandline4 = $_POST['mobileLandline4'] ;
$mobileLandline5 = $_POST['mobileLandline5'] ;
$mobileLandline6 = $_POST['mobileLandline6'] ;
$mobileLandline7 = $_POST['mobileLandline7'] ;
$mobileLandline8 = $_POST['mobileLandline8'] ;
//
$language = $_POST['language'] ;
//
$address = $_POST['address'] ;
$city = $_POST['city'] ;
$state = $_POST['state'] ;
$pin = $_POST['pin'] ;
//
$fax = $_POST['fax'] ;
$email = $_POST['email'] ;
//
$passwordOption = $_POST['passwordOption'] ;
$passwordOptionProvided = $_POST['passwordOptionProvided'] ;
//Using PHPMailer with GMAIL
include("class.phpmailer.php");
include("class.smtp.php"); // note, this is optional - gets called from main class if not already loaded
$mail = new PHPMailer();
$body = $mail->getFile('email-content.php');
$body = eregi_replace("[\]",'',$body);
$mail->IsSMTP();
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port
$mail->Username = "####@gmail.com"; // GMAIL username
$mail->Password = "#######"; // GMAIL password
$mail->From = "subscriptionForm@abc.com";
$mail->FromName = "Subscrition Form";
$mail->Subject = "SUBSCRIPTION FORM DETAILS FROM WEBSITE";
$mail->AltBody = "This is the body when user views in plain text format"; //Text Body
$mail->WordWrap = 50; // set word wrap
$mail->MsgHTML($body);
$mail->AddReplyTo("replyto@yourdomain.com","Webmaster, ####.com");
$mail->AddEmbeddedImage('logo.png', 'logo');
//$mail->AddAttachment("/path/to/file.zip"); // attachment
//$mail->AddAttachment("/path/to/image.jpg", "new.jpg"); // attachment
$mail->AddAddress("contact@abcd.com","Subscription Form");
$mail->IsHTML(true); // send as HTML
if(!$mail->Send()) {
header('Location: http://www.#####.com/subscription-form-fail.html');
} else {
//echo "Message has been sent";
// header('Location: $submissionsuccess');
header('Location: http://www.####.com/subscription-form-success.html');
}
?>
email-content.php的代码:(部分将php数据值调用到HTML模板中)
<table width="590" border="0" cellspacing="0" cellpadding="0" >
<tr>
<td align="left" valign="top" width="50" style="font-size:10pt; font-family:Tahoma, Geneva, sans-serif; padding:2px;">Name :</td>
<td align="left" valign="top" width="30" style="font-size:10pt; font-family:Tahoma, Geneva, sans-serif; padding:2px;"><?php $salutation ?></td>
<td align="left" valign="top" width="460" style="font-size:10pt; font-family:Tahoma, Geneva, sans-serif;">
<table width="460" border="1" cellspacing="0" cellpadding="0" style=" border-collapse:collapse;font-size:10pt; font-family:Tahoma, Geneva, sans-serif;border:1px solid #e0e3e5;" >
<tr>
<td style="padding:2px;"><?php $_POST['name'] ?></td>
</tr>
</table>
我是php编程的新手,我确定我错过了一些非常基本的东西。提交的HTML电子邮件中不会显示提交的名称值。
任何有关此事的指导都应受到高度赞赏
由于
穆迪
答案 0 :(得分:1)
找到了解决方案。
1。在电子邮件模板代码中,表单值将被称为%name%,例如名称值
2。在名为FORM SUBMISSION的PHP代码中,将%ith替换为实际信息,如下所示:
$ body = str_replace('%name%',$ name,$ body);
这很好用。