I have a php form that sends an email, however I would like to put the headings of each section in bold but can't seem to get it to work from everywhere I've searched.
The form:
$email_message .= "Name: ".clean_string($firstlastname)."\n\n";
$email_message .= "Email: ".clean_string($email_from)."\n\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n\n";
$email_message .= "Property Type: ".clean_string($ptype)."\n\n";
$email_message .= "From Address: ".clean_string($faddress)."\n\n";
$email_message .= "To Address: ".clean_string($taddress)."\n";
$email_message .= "Moving Items Description: ".clean_string($itemsdescription)."\n\n";
$email_message .= "Dissasembling Requirements: ".clean_string($disassemble)."\n\n";
$email_message .= "Packaging Requirements: ".clean_string($packaging)."\n\n";
$email_message .= "Preferred Date and Time: ".clean_string($dateandtime)."\n\n";
$email_message .= "Property Access: ".clean_string($paccess)."\n\n";
$email_message .= "Stair Count: ".clean_string($staircount)."\n\n";
$email_message .= "Message: ".clean_string($message)."\n\n";
// create email headers
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
#mail($email_to, $email_subject, $email_message, $headers);
?>
I've tried adding the bold and strong tags to the headings;
$email_message .= "<b>Name:</b> ".clean_string($firstlastname)."\n\n";
Still not working, including setting it outside of the heading of the text.
Edit: this is the full form
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "email#email.com";
$email_subject = "Contact Form Submission";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['firstlastname']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['ptype']) ||
!isset($_POST['faddress']) ||
!isset($_POST['taddress']) ||
!isset($_POST['itemsdescription']) ||
!isset($_POST['disassemble']) ||
!isset($_POST['packaging']) ||
!isset($_POST['dateandtime']) ||
!isset($_POST['paccess']) ||
!isset($_POST['staircount']) ||
!isset($_POST['message'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$firstlastname = $_POST['firstlastname'];
$email_from = $_POST['email'];
$telephone = $_POST['telephone'];
$ptype = $_POST['ptype'];
$faddress = $_POST['faddress'];
$taddress = $_POST['taddress'];
$itemsdescription = $_POST['itemsdescription'];
$disassemble = $_POST['disassemble'];
$packaging = $_POST['packaging'];
$dateandtime = $_POST['dateandtime'];
$paccess = $_POST['paccess'];
$staircount = $_POST['staircount'];
$message = $_POST['message'];
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$firstlastname)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(strlen($message) < 2) {
$error_message .= 'The Comments you entered do not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Name: ".clean_string($firstlastname)."\n\n";
$email_message .= "Email: ".clean_string($email_from)."\n\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n\n";
$email_message .= "Property Type: ".clean_string($ptype)."\n\n";
$email_message .= "From Address: ".clean_string($faddress)."\n\n";
$email_message .= "To Address: ".clean_string($taddress)."\n";
$email_message .= "Moving Items Description: ".clean_string($itemsdescription)."\n\n";
$email_message .= "Dissasembling Requirements: ".clean_string($disassemble)."\n\n";
$email_message .= "Packaging Requirements: ".clean_string($packaging)."\n\n";
$email_message .= "Preferred Date and Time: ".clean_string($dateandtime)."\n\n";
$email_message .= "Property Access: ".clean_string($paccess)."\n\n";
$email_message .= "Stair Count: ".clean_string($staircount)."\n\n";
$email_message .= "Message: ".clean_string($message)."\n\n";
// create email headers
$headers = "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
#mail($email_to, $email_subject, $email_message, $headers);
?>
<!-- include your own success html here -->
<script>window.location.replace("index.html");</script>
<?php
}
?>
You missed a dot to append more headers. This overwrites your Content-Type and that is why it is parsing the email as text and not has HTML
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers .= 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
#mail($email_to, $email_subject, $email_message, $headers);
?>
Could you try :
$email_message .= "<strong>Name:</strong> ".clean_string($firstlastname)."\n\n";
or
$email_message .= "<b>Name:</b> ".clean_string($firstlastname)."\n\n";
or
$email_message .= "<p style="font-weight: bold;">Name:</b> ".clean_string($firstlastname)."\n\n";
Use PHP Mailer plugin.
Download Plugin in following link:
https://github.com/PHPMailer/PHPMailer/releases/tag/v5.2.26
$mail_message='Dear '.$row[0]['branch_name'].','. "\r\n";
$mail_message.='Thanks for contacting regarding to forgot password,<br> Your <b>Password</b> is <b>'.$passwordplain.'</b>'."\r\n";
$mail_message.='<br>Please Update your password.';
$mail_message.='<br>Thanks & Regards';
$mail_message.='<br>Test group of company';
date_default_timezone_set('Etc/UTC');
require FCPATH.'application/libraries/PHPMailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
// $mail->isSMTP();
$mail->SMTPSecure = "ssl";
$mail->Debugoutput = 'html';
$mail->Host = "(HOST SERVER)";
$mail->Port = 465;
$mail->SMTPAuth = true;
$mail->Username = "(USERNAME)";
$mail->Password = "(PASSWORD)";
$mail->setFrom('(FROM MAIL ADDRESS)', 'Test group of company');
$mail->IsHTML(true);
$mail->addAddress($email);
$mail->Subject = 'New password for login';
$mail->Body = $mail_message;
if (!$mail->send()) {
$data['message_display'] = 'Failed to send password, please try again!';
$this->load->view('branch/forgotPassword', $data);
} else {
$data['message_display'] = 'Password sent to your email!';
$this->load->view('branch/forgotPassword', $data);
}
Related
I am relatively new to php but learning as I go. I am creating a tenant application form for my business, and have got the form working with basic text, dropdown fields, etc. Now I need to add a file upload to the form that will be sent to my email.
Can anyone please spare the time to add in the file upload as an attachment as I've tried a few different code snippets but struggled with it.
the HTML for the form is quite lengthy, I will post it if required but i have added enctype="multipart/form-data" to the form tab, name for inout is file_upload.
Heres my form handler, which may well be a long way round but it works presently
if(isset($_POST['email'])) {
$email_to = "REMOVED";
$email_subject = "TENANT APPLICATION";
function died($error) {
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
$property = $_POST['property'];
$title = $_POST['title'];
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$dateofbirth = $_POST['dateofbirth'];
$nationality = $_POST['nationality'];
$email_from = $_POST['email'];
$telephone = $_POST['telephone'];
$natins = $_POST['natins'];
$smoker = $_POST['smoker'];
$bankrupt = $_POST['bankrupt'];
$ccj = $_POST['ccj'];
$currentaddress = $_POST['currentaddress'];
$tenancy = $_POST['tenancy'];
$timeataddress = $_POST['timeataddress'];
$employmentstatus = $_POST['employmentstatus'];
$company = $_POST['company'];
$positionheld = $_POST['positionheld'];
$salary = $_POST['salary'];
$timeatemployer = $_POST['timeatemployer'];
$selfemployedinfo = $_POST['selfemployedinfo'];
$selfemployedincome = $_POST['selfemployedincome'];
$otheroccupantsover18 = $_POST['otheroccupantsover18'];
$otheroccupantsunder18 = $_POST['otheroccupantsunder18'];
$pets = $_POST['pets'];
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$first_name)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp,$last_name)) {
$error_message .= 'The Last Name you entered does not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Property applied for: ".clean_string($property)."\n\n";
$email_message .= "APPLICANT DETAILS.\n\n";
$email_message .= "Title: ".clean_string($title)."\n";
$email_message .= "First name: ".clean_string($first_name)."\n";
$email_message .= "Last name: ".clean_string($last_name)."\n";
$email_message .= "Date of birth: ".clean_string($dateofbirth)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .= "National insurance : ".clean_string($natins)."\n";
$email_message .= "Smoker : ".clean_string($smoker)."\n";
$email_message .= "Bankrupt : ".clean_string($bankrupt)."\n";
$email_message .= "CCJ's : ".clean_string($ccj)."\n\n";
$email_message .= "CURRENT ADDRESS DETAILS.\n\n";
$email_message .= "Current address: ".clean_string($currentaddress)."\n";
$email_message .= "Type of tenancy: ".clean_string($tenancy)."\n";
$email_message .= "Time at current address: ".clean_string($timeataddress)."\n\n";
$email_message .= "PREVIOUS ADDRESS DETAILS.\n\n";
$email_message .= "Previous address 1: ".clean_string($previousaddressone)."\n";
$email_message .= "Previous address 2: ".clean_string($previousaddresstwo)."\n\n";
$email_message .= "EMPLOYMENT.\n\n";
$email_message .= "Employment status: ".clean_string($employmentstatus)."\n\n";
$email_message .= "EMPLOYED DETAILS.\n\n";
$email_message .= "Company: ".clean_string($company)."\n";
$email_message .= "Position held: ".clean_string($positionheld)."\n";
$email_message .= "Salary: ".clean_string($salary)."\n";
$email_message .= "Time with employer: ".clean_string($timeatemployer)."\n\n";
$email_message .= "SELF EMPLOYED DETAILS.\n\n";
$email_message .= "Details of self employment: ".clean_string($selfemployedinfo)."\n";
$email_message .= "Average net income of past 3 years: ".clean_string($selfemployedincome)."\n\n";
$email_message .= "OTHER OCCUPANTS.\n\n";
$email_message .= "Other occupants OVER 18: ".clean_string($otheroccupantsover18)."\n";
$email_message .= "Other occupants UNDER 18: ".clean_string($otheroccupantsunder18)."\n";
$email_message .= "Details of any pets: ".clean_string($pets)."\n\n";
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
#mail($email_to, $email_subject, $email_message, $headers);
?>
<?php include 'thankyouapplicationform.php';?>
<?php
}
I have successfully got the following code working but this was a code snippet downloaded from somewhere, and i failed to merge the file upload part into my form handler
''' <?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
/*
Tested working with PHP5.4 and above (including PHP 7 )
*/
require_once './vendor/autoload.php';
use FormGuide\Handlx\FormHandler;
$pp = new FormHandler();
$validator = $pp->getValidator();
$validator->fields(['Name','Email'])->areRequired()->maxLength(50);
$validator->field('Email')->isEmail();
$validator->field('Message')->maxLength(6000);
$pp->attachFiles(['image']);
$pp->sendEmailTo('REMOVED'); // ↠Your email here
echo $pp->process($_POST); '''
Edit Here are the attempts I've made so far...
When a user fills the form I receive the details via mail using my code. That seems to be working fine but my concern is how do I set auto mail reply in my code?
Whenever user submits the form he should get a automated reply like "Thanks for contacting" .
How do i achieve that?
<?php
if(isset($_POST['email'])) {
$email_to = "demo#xyz.com";
$email_subject = "Contact Form Details";
function died($error) {
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
if(!isset($_POST['name']) ||
!isset($_POST['subject']) ||
!isset($_POST['email']) ||
!isset($_POST['phone']) ||
!isset($_POST['message'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$first_name = $_POST['name']; // required
$last_name = $_POST['subject']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['phone']; // not required
$comments = $_POST['message']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$first_name)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp,$last_name)) {
$error_message .= 'The Last Name you entered does not appear to be valid.<br />';
}
if(strlen($comments) < 2) {
$error_message .= 'The Comments you entered do not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "First Name: ".clean_string($first_name)."\n";
$email_message .= "Subject: ".clean_string($last_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .= "Comments: ".clean_string($comments)."\n";
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
#mail($email_to, $email_subject, $email_message, $headers);
?>
Thank you for contacting me. I will be in touch with you very soon.
<?php
}
?>
Also how to reset the form after successful submit?
Even if this is not done its okay but auto reply is very important for me.
Just send a second email, one to you with details and one to the sender with auto response message.
//your existing code
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
#mail($email_to, $email_subject, $email_message, $headers);
//add this
$headers = 'From: '.$email_to."\r\n".
'Reply-To: '.$email_to."\r\n" .
'X-Mailer: PHP/' . phpversion();
#mail($email_from, "Thanks For reaching Out", "Auto Reply - Do Not Respond", $headers);
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 5 years ago.
I have looked for a solution to my problem all over but cant seem to get it to work.
I have a form that gets data from the user and then emails it to me when they click submit.
I would also like them to receive an confirmation email to the address they provided, and this is where I am stuck.
If the form is required please ask and I will send, but here is the PHP...
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "webhost#compumodsa.com";
$email_subject = "CompuMod Web-site Order";
function died($error) {
// your error code can go here
echo "Something was entered incorrectly…";
echo "Please correct the following.<br /><br />";
echo $error."<br /><br />";
echo "After correcting, please try again.<br /><br />";
die();
}
// validation expected data exists
if(
!isset($_POST['site']) ||
!isset($_POST['page']) ||
!isset($_POST['domain']) ||
!isset($_POST['host']) ||
!isset($_POST['service']) ||
!isset($_POST['firstname']) ||
!isset($_POST['lastname']) ||
!isset($_POST['company']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['idnumber']) ||
!isset($_POST['address']) ||
!isset($_POST['suburb']) ||
!isset($_POST['city']) ||
!isset($_POST['province']) ||
!isset($_POST['postcode']) ||
!isset($_POST['comments'])) {
died('Something was entered incorrectly…');
}
$site = $_POST['site']; // required
$page = $_POST['page']; // required
$domain = $_POST['domain']; // required
$host = $_POST['host']; // required
$service = $_POST['service']; // required
$firstname = $_POST['firstname']; // required
$lastname = $_POST['lastname']; // required
$company = $_POST['company']; // not required
$email = $_POST['email']; // required
$telephone = $_POST['telephone']; // required
$idnumber = $_POST['idnumber']; // required
$address = $_POST['address']; // required
$suburb = $_POST['suburb']; // not required
$city = $_POST['city']; // required
$province = $_POST['province']; // required
$postcode = $_POST['postcode']; // required
$comments = $_POST['comments']; // not required
$error_message = "";
$string_exp = "/^[0-9]+$/";
if(!preg_match($string_exp,$site)) {
$error_message .= 'Your “Base Site Design” was not Selected.<br />';
}
$string_exp = "/^[0-9]+$/";
if(!preg_match($string_exp,$page)) {
$error_message .= 'Your “Extra Pages” was not Selected.<br />';
}
$string_exp = "/^[0-9]+$/";
if(!preg_match($string_exp,$domain)) {
$error_message .= 'Your “Domain Registration” was not Selected.<br />';
}
$string_exp = "/^[0-9]+$/";
if(!preg_match($string_exp,$host)) {
$error_message .= 'Your “Host Server Size” was not Selected.<br />';
}
$string_exp = "/^[0-9]+$/";
if(!preg_match($string_exp,$service)) {
$error_message .= 'Your “Service Package” was not Selected.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$firstname)) {
$error_message .= 'Your “First Name” was not entered or entered incorrectly.<br />';
}
if(!preg_match($string_exp,$lastname)) {
$error_message .= 'Your “Last Name” was not entered or entered incorrectly.<br />';
}
$email_exp = '/^[A-Za-z0-9._%-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email)) {
$error_message .= 'Your “E-Mail” was not entered or entered incorrectly.<br />';
}
$string_exp = "/^[0-9]+$/";
if(!preg_match($string_exp,$telephone)) {
$error_message .= 'Your “Phone/Cell” was not entered or entered incorrectly.<br />';
}
$string_exp = "/^[0-9]+$/";
if(!preg_match($string_exp,$idnumber)) {
$error_message .= 'Your “SA ID Number” was not entered or entered incorrectly.<br />';
}
$string_exp = "/^[A-Za-z0-9 .'-]+$/";
if(!preg_match($string_exp,$address)) {
$error_message .= 'Your “Street Address” was not entered or entered incorrectly.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$city)) {
$error_message .= 'Your “City” was not entered or entered incorrectly.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$province)) {
$error_message .= 'Your “Povince” was not entered or entered incorrectly.<br/>';
}
$string_exp = "/^[0-9]+$/";
if(!preg_match($string_exp,$postcode)) {
$error_message .= 'Your “Postal Code” was not entered or entered incorrectly.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Client request details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
//request email variables
$email_message .= "Base Site Design: - ".clean_string($site)."\n";
$email_message .= "Extra Pages: - ".clean_string($page)."\n";
$email_message .= "Domain Registration: - ".clean_string($domain)."\n";
$email_message .= "Host Server Size: - ".clean_string($host)."\n";
$email_message .= "Service Package: - ".clean_string($service)."\n";
$email_message .= "First Name: - ".clean_string($firstname)."\n";
$email_message .= "Last Name: - ".clean_string($lastname)."\n";
$email_message .= "Company: - ".clean_string($company)."\n";
$email_message .= "E-Mail: - ".clean_string($email)."\n";
$email_message .= "Phone/Cell: - ".clean_string($telephone)."\n";
$email_message .= "SA ID Number: - ".clean_string($idnumber)."\n";
$email_message .= "Address: - ".clean_string($address)."\n";
$email_message .= "Suburb: - ".clean_string($suburb)."\n";
$email_message .= "City: - ".clean_string($city)."\n";
$email_message .= "Province: - ".clean_string($province)."\n";
$email_message .= "Postal Code: - ".clean_string($postcode)."\n";
$email_message .= "Extra Requests: - ".clean_string($comments)."\n";
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
#mail($email_to, $email_subject, $email_message, $headers);
//conformation email variables
$subject = "Welcome & Thanks!";
$email_message = "Thank you ".clean_string($firstname)." ".clean_string($lastname)." for your request\n\n";
$email_message .= "A Compumod representative will contact you as soon as posable.\n";
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email."\r\n" .
'X-Mailer: PHP/' . phpversion();
#mail($email, $subject, $email_message, $headers);
header('Location: http://www.compumodsa.com/index.php/component/k2/item/21');
?>
<!-- include your own success html here -->
<?php
}
?>
The form details gets emailed to me with...
//request email variables
$email_message .= "Base Site Design: - ".clean_string($site)."\n";
$email_message .= "Extra Pages: - ".clean_string($page)."\n";
$email_message .= "Domain Registration: - ".clean_string($domain)."\n";
$email_message .= "Host Server Size: - ".clean_string($host)."\n";
$email_message .= "Service Package: - ".clean_string($service)."\n";
$email_message .= "First Name: - ".clean_string($firstname)."\n";
$email_message .= "Last Name: - ".clean_string($lastname)."\n";
$email_message .= "Company: - ".clean_string($company)."\n";
$email_message .= "E-Mail: - ".clean_string($email)."\n";
$email_message .= "Phone/Cell: - ".clean_string($telephone)."\n";
$email_message .= "SA ID Number: - ".clean_string($idnumber)."\n";
$email_message .= "Address: - ".clean_string($address)."\n";
$email_message .= "Suburb: - ".clean_string($suburb)."\n";
$email_message .= "City: - ".clean_string($city)."\n";
$email_message .= "Province: - ".clean_string($province)."\n";
$email_message .= "Postal Code: - ".clean_string($postcode)."\n";
$email_message .= "Extra Requests: - ".clean_string($comments)."\n";
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
#mail($email_to, $email_subject, $email_message, $headers);
The conformation email witch is suppose to go to the user...
//conformation email variables
$subject = "Welcome & Thanks!";
$email_message = "Thank you ".clean_string($firstname)." ".clean_string($lastname)." for your request\n\n";
$email_message .= "A Compumod representative will contact you as soon as posable.\n";
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email."\r\n" .
'X-Mailer: PHP/' . phpversion();
#mail($email, $subject, $email_message, $headers);
no email is being received by the user.
All help would be so much appreciated...
Not sure what you are trying to do here, but this would likely be where your problem lies...
if($_POST['email'] == "post")
{
//email variables
$subject = "Indie Rally - Welcome & Thanks!";
$email_message = "Thank you ".clean_string($firstname)." ".clean_string($lastname)."for your request\n\n";
$email_message .= "A Compumod representative will contact you as soon as posable.\n";
// create email headers
$headers = 'From: webhost#compumodsa.com' . "\r\n" .
'Reply-To: $email' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($email, $subject, $email_message, $headers);
}
Assuming that $_POST['email'] is the email address of the person filling out the form, seeing if it equals the obviously invalid email address of "post" is either A) always going to fail the conditional check or B) pass the conditional check and pass an invalid "To:" address to the PHP mail function.
Since you have already performed the tests previously to ensure that the email address is both existing and valid, you should not require that conditional around the auto-responder functionality at all. Just send the email.
This will leave you with this...
/*
* Notice the removal of the `if()` statement
*/
//email variables
$subject = "Indie Rally - Welcome & Thanks!";
$email_message = "Thank you ".clean_string($firstname)." ".clean_string($lastname)."for your request\n\n";
$email_message .= "A Compumod representative will contact you as soon as posable.\n";
// create email headers
$headers = 'From: webhost#compumodsa.com' . "\r\n" .
'Reply-To: $email' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($email, $subject, $email_message, $headers);
When someone fills out a form on our website it uses the person filling out the forms email address. Our hosting company is blocking the emails because the person filling out the form is set as the 'From'. From our hosting company:
"You'll need to ensure that the form is permanently set with a DreamHost
hosted email address so that this form works properly and isn't rejected.
It may be set so that the person filling out the form is being set as the
'From', which will result in the rejection above.
Just edit the form so that the 'From' is permanently set to a DH user so
that the form is no longer rejected due to policy reasons."
What changes do I need to make to the below code to make this acceptable to Dreamhost? Any help would be greatly appreciated.
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "eileenw#ourdomain.com";
$email_subject = "Quiz";
$your_email = "info#ourdomain.com";
function died($error) {
// your error code can go here
echo "<p>We are very sorry, but there were error(s) found with the form you submitted.</p> ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "<p>Please go back and fix these errors.<br /><br /></p>";
die();
}
// validation expected data exists
if(!isset($_POST['first_name']) ||
!isset($_POST['last_name']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['comments'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$address = $_POST['address']; // not required
$city = $_POST['city']; // not required
$state = $_POST['state']; // not required
$vehicleyear = $_POST['vehicleyear']; // not required
$vehiclemake = $_POST['vehiclemake']; // not required
$vehiclemodel = $_POST['vehiclemodel']; // not required
$purchase_or_lease = $_POST['purchase_or_lease']; // not required
$deliverydate = $_POST['deliverydate']; // not required
$mileage_at_delivery = $_POST['mileage_at_delivery']; // not required
$current_mileage = $_POST['current_mileage']; // not required
$seller = $_POST['seller']; // not required
$citystate = $_POST['citystate']; // not required
$Bank_Finance = $_POST['Bank_Finance']; // not required
$dealer_arranged = $_POST['dealer_arranged']; // not required
$employee_discount = $_POST['employee_discount']; // not required
$warranty = $_POST['warranty']; // not required
$length_contract = $_POST['length_contract']; // not required
$comments = $_POST['comments']; // not required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$first_name)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp,$last_name)) {
$error_message .= 'The Last Name you entered does not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "First Name: ".clean_string($first_name)."\n";
$email_message .= "Last Name: ".clean_string($last_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .= "Address: ".clean_string($address)."\n";
$email_message .= "City: ".clean_string($city)."\n";
$email_message .= "State: ".clean_string($state)."\n";
$email_message .= "Vehicle Year: ".clean_string($vehicleyear)."\n";
$email_message .= "Make: ".clean_string($vehiclemake)."\n";
$email_message .= "Model: ".clean_string($vehiclemodel)."\n";
$email_message .= "Purchase or Lease: ".clean_string($purchase_or_lease)."\n";
$email_message .= "Delivery date: ".clean_string($deliverydate)."\n";
$email_message .= "Mileage at Delivery: ".clean_string($mileage_at_delivery)."\n";
$email_message .= "Current Mileage: ".clean_string($current_mileage)."\n";
$email_message .= "Selling Dealer: ".clean_string($seller)."\n";
$email_message .= "Seller City and State: ".clean_string($citystate)."\n";
$email_message .= "Bank or Finance Company: ".clean_string($Bank_Finance)."\n";
$email_message .= "Dealer Arranged: ".clean_string($dealer_arranged)."\n";
$email_message .= "Employee Discount? ".clean_string($employee_discount)."\n";
$email_message .= "Warranty: ".clean_string($warranty)."\n";
$email_message .= "Contract Terms: ".clean_string($length_contract)."\n";
$email_message .= "Comments: ".clean_string($comments)."\n";
// create email headers
$headers = 'From: ' . $your_email . "\r\n";
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
#mail($email_to, $email_subject, $email_message, $headers);
?>
According to your hosting provider:
Just edit the form so that the 'From' is permanently set to a DH user
So if I were to guess, I suspect that the change you need to make is to modify the From header. This is where you set it:
$headers = 'From: ' . $your_email . "\r\n";
So set it to something else:
$headers = 'From: someknownaddress#dreamhost.com' . "\r\n";
I am trying to get a file to upload as part of a contact form, i would like the uploaded file to end up as an attachement to an email that i can then download once i have received said email. I have got the form to work but instead of coming through as an attachment my file comes through like this;
--==Multipart_Boundary_xc99bf5ef644b3e51650e68e4b9538cffx
Content-Type: application/pdf;
name="360x260mm Side Seam Pocket 01 - 1up B2.pdf"
Content-Transfer-Encoding: base64
JVBERi0xLjUNJeLjz9MNCjggMCBvYmoNPDwvTWV0YWRhdGEgOSAwIFIvT0NQcm9wZXJ0aWVzPDwv
RDw8L09OWzEwIDAgUl0vT3JkZXIgMTEgMCBSL1JCR3JvdXBzW10+Pi9PQ0dzWzEwIDAgUl0+Pi9Q
YWdlcyAyIDAgUi9UeXBlL0NhdGFsb2c+Pg1lbmRvYmoNOSAwIG9iag08PC9MZW5ndGggMTM0NTEv
U3VidHlwZS9YTUwvVHlwZS9NZXRhZGF0YT4+c3RyZWFtDQo8P3hwYWNrZXQgYmVnaW49Iu+7vyIg
aWQ9Ilc1TTBNcENlaGlIenJlU3pOVGN6a2M5ZCI/Pgo8eDp4bXBtZXRhIHhtbG5zOng9ImFkb2Jl
Om5zOm1ldGEvIiB4OnhtcHRrPSJBZG9iZSBYTVAgQ29yZSA1LjAtYzA2MCA2MS4xMzQ3NzcsIDIw
MTAvMDIvMTItMTc6MzI6
Here is my php;
<?php
if(isset($_POST['email'])) {
$email_to = "matthew.p#cawthornes.co.uk";
$email_subject = "website html form submissions";
function died($error) {
// error code
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['first_name']) ||
!isset($_POST['last_name']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['service']) ||
!isset($_POST['comments'])){
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$service = $_POST['service']; // not required
$comments = $_POST['comments']; // required
/* GET File Variables */
$tmpName = $_FILES['attachment']['tmp_name'];
$fileType = $_FILES['attachment']['type'];
$fileName = $_FILES['attachment']['name'];
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$first_name)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp,$last_name)) {
$error_message .= 'The Last Name you entered does not appear to be valid.<br />';
}
if(strlen($comments) < 2) {
$error_message .= 'The Comments you entered do not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
if (file($tmpName)) {
/* Reading file ('rb' = read binary) */
$file = fopen($tmpName,'rb');
$data = fread($file,filesize($tmpName));
fclose($file);
/* a boundary string */
$randomVal = md5(time());
$mimeBoundary = "==Multipart_Boundary_x{$randomVal}x";
/* Header for File Attachment */
$headers .= "\nMIME-Version: 1.0\n";
$headers .= "Content-Type: multipart/mixed;\n" ;
$headers .= " boundary=\"{$mimeBoundary}\"";
/* Multipart Boundary above message */
$message = "This is a multi-part message in MIME format.\n\n" .
"--{$mimeBoundary}\n" .
"Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message . "\n\n";
/* Encoding file data */
$data = chunk_split(base64_encode($data));
}
$email_message .= "First Name: ".clean_string($first_name)."\n";
$email_message .= "Last Name: ".clean_string($last_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .= "Service: ".clean_string($service)."\n";
$email_message .= "Comments: ".clean_string($comments)."\n";
/* Adding attchment-file to message*/
$email_message .= "--{$mimeBoundary}\n" .
"Content-Type: {$fileType};\n" .
" name=\"{$fileName}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mimeBoundary}--\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
#mail($email_to, $email_subject, $email_message, $headers);
function IsInjected($str)
{
$injections = array('(\n+)',
'(\r+)',
'(\t+)',
'(%0A+)',
'(%0D+)',
'(%08+)',
'(%09+)'
);
$inject = join('|', $injections);
$inject = "/$inject/i";
if(preg_match($inject,$str))
{
return true;
}
else
{
return false;
}
}
?>
<!-- success html -->
Thank you for contacting us. We will be in touch with you very soon.
<?php
}
die();
?>
Thanks in advance.
Why dont you use Swift Mailer
Docs : Swift Mailer Documentation
Downloads : Swift-5.1.0
require_once 'lib/swift_required.php';
// Create the message
$message = Swift_Message::newInstance()
// Give the message a subject
->setSubject('Your subject')
// Set the From address with an associative array
->setFrom(array('john#doe.com' => 'John Doe'))
// Set the To addresses with an associative array
->setTo(array('receiver#domain.org', 'other#domain.org' => 'A name'))
// Give it a body
->setBody('Here is the message itself')
// And optionally an alternative body
->addPart('<q>Here is the message itself</q>', 'text/html')
// Optionally add any attachments
->attach(Swift_Attachment::fromPath('my-document.pdf'));