Reputation: 235
Hi guys, i have a very basic php issue about adding form data into html/php file being sent using phpmailer
Im using gmail account SMTP to send HTML email on successful submission of form.
On Form submission the HTML email is being successfully sent.
PROBLEM / ISSUE:
Im unable to attach the FORM DATA inputted into various headers in the HTML file that im sending as email.
THIS IS THE CODE OF PHP CALLED : for FORM SUBMISSION. email-content.php is the file that is successfully sent as HTML email using Gmail SMTP.
<?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');
}
?>
THE CODE OF email-content.php : (part ho im calling php data value into HTML template)
<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>
Im a novice in php programming and im sure im missing something very basic here. The name values submited are NOT visible in the HTML email sent.
Any guidance in this matter shall be highly appreciated
Thanks
Moody
Upvotes: 0
Views: 1693
Reputation: 235
Found the solution.
1. In the email template code the form values to be called as %name% for say name value
2. In the PHP code called for FORM SUBMISSION, replace the % ith the actual information like so:
$body = str_replace('%name%', $name, $body);
This works just fine.
Upvotes: 1