2013-02-26 76 views
0

嗨,你们正在通过电子邮件发送,我对将表单数据转换成HTML/PHP文件一个非常基本的PHP问题,使用PHPMailer的添加表单数据到HTML文件中使用的PHPMailer

发送即时通讯使用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  = "[email protected]"; 
$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("[email protected]","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("[email protected]","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'); 
} 

?> 

电子邮件content.php守则:(部分豪IM调用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编程和IM确保我在想念这里非常基本的东西。提供的名称值在发送的HTML电子邮件中不可见。

在这个问题上的任何指导应高度赞赏

由于

穆迪

回答

1

找到了解决办法。

1.在电子邮件模板代码的形式值被称为%名字%的发言权名值

2.在呼吁表单提交的PHP代码,第i个像这样的实际信息替换%: $ body = str_replace('%name%',$ name,$ body);

这工作得很好。

相关问题