I am using the Mail() function in attempts to send mail via a form on a web page (same page as the form by using a custom function). The function worked just fine until I tried to add more information to it and attempted to create an HTML-formatted e-mail.
Now, the visitor comes to the form and fills in the required field with JavaScript validator to ensure that all required fields get filled in correctly.
Once the visitor gets all the required info done, they click submit. Now, I have an if statement checking for a querystring which will only be there if the form is posted and tell the page to process, displaying a confirmation message. Otherwise the form will simply be displayed again with no fields filled in.
The tricky thing here that I am trying to do is use a template, "email_temp.tpl", and fill in the places where information is entered to customize the e-mail.
The form submits as intended and I am getting the confirmation display, but something is going wrong before the Mail() function gets called, because I am not getting the e-mails. Here is the code:
Code: Select all
function send_mail(){
$file_name="email_temp.tpl";
$send_to="info@domainname.com";
$headers_to_write=return_all_headers();
$subject="General Inquiry Submission";
$email_body=implode("",file($file_name));
$email_body=str_replace("[>email_subject<]",trim($subject),$email_body);
$email_body=str_replace("[>subject<]",trim($cmbInquiry),$email_body);
$email_body=str_replace("[>header_info<]",$headers_to_write,$email_body);
$email_body=str_replace("[>name<]",trim($txtName),$email_body);
$email_body=str_replace("[>email<]",trim($txtEMail),$email_body);
$email_body=str_replace("[>phone1<]",trim($txtDaytimePhone),$email_body);
$email_body=str_replace("[>phone2<]",trim($txtEveningPhone),$email_body);
$email_body=str_replace("[>address<]",trim($txtAddress),$email_body);
$email_body=str_replace("[>address2<]",trim($txtAddress2),$email_body);
$email_body=str_replace("[>city<]",trim($txtCity),$email_body);
$email_body=str_replace("[>state<]",trim($cmbState),$email_body);
$email_body=str_replace("[>zip<]",trim($txtZipCode),$email_body);
$email_body=str_replace("[>country<]",trim($txtCountry),$email_body);
$email_body=str_replace("[>how<]",trim($cmbReferredBy),$email_body);
$email_body=str_replace("[>contact<]",trim($cmbPreferredContact),$email_body);
$email_body=str_replace("[>comments<]",trim($txtComments),$email_body);
$email_body=addslashes($email_body);
$email_body=chunk_split(base64_encode($email_body))."\n \n";
$email_headers ="MIME-Version: 1.0\r \n";
$email_headers.="To: StrohlSiteDesign.com<$send_to>\r \n";
$email_headers.="From: $txtName<$txtEMail>\r \n";
$email_headers.="Reply-To: $txtName<$txtEMail>\r \n";
$email_headers.="X-Priority: 1\r \n";
$email_headers.="X-MSMail-Priority: High\r \n";
$email_headers.="X-Mailer: PHP Mailer\r \n";
$email_headers.="Content-Type: text/html; charset="iso-8859-1"\r \n";
$email_headers.="Content-Transfer-Encoding: base64\r \n \n";
if (mail($send_to,$subject,stripslashes($email_body),$email_headers)) {
return 1;
}else{
return 0;
}
}
function return_all_headers() {
$headers = array();
while (list($key, $value) = each ($_SERVER)) {
if (strncmp($key, "HTTP_", 5) == 0) {
$key = strtr(ucwords(strtolower(strtr(substr($key, 5), "_", " "))), " ", "-");
$headers[$key] = $value;
}
}
return $headers;
}Any help is greatly appreciated... It is still appreciated if you tell me that I need to start over with a new way of doing what I want to do. Hehehe...