html link in php mail? - php

So I have this line in my php form processor:
$automessage = 'Thanks for requesting a sample from us! We have received your information, so please expect your sample shortly. In the meantime, be sure to connect with us on Facebook!';
But the link still shows up as plain text, even though I have this header:
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
Is my formatting for the link incorrect?
EDIT: Here is the entire script:
<?php
// CLIENT INFORMATION
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];
$company = $_POST['company'];
$address = $_POST['address'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$phone = $_POST['phone'];
// MODIFY THE FOLLOWING SECTION
// your name
$recipientname = "company";
// your email
$recipientemail = "me#company.com";
// subject of the email sent to you
$subject = "Sample Request for $recipientname";
// send an autoresponse to the user?
$autoresponse = "yes";
// subject of autoresponse
$autosubject = "Thank you for your sample request!";
// autoresponse message
$automessage = 'Thanks for requesting a sample from company! We have received your information, so please expect your sample shortly. In the meantime, be sure to connect with us on Facebook and Twitter!';
// thankyou displayed after the user clicks "submit"
$thanks = "Thank you for contacting us. We will get back to you as soon as possible.";
// END OF NECESSARY MODIFICATIONS
// format message
$message = "New sample request for $recipientname:
<br>
<br>
First Name: $firstname
<br>
Last Name: $lastname
<br>
Email: $email
<br>
Company: $company
<br>
Address: $address
<br>
City: $city
<br>
State: $state
<br>
Zip: $zip
<br>
Phone: $phone
<br>
--
<br>";
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'From: company <me#company.com>' . "\r\n";
// send mail and print success message
mail($recipientemail, $subject, $message, $headers);
if($autoresponse == "yes") {
$autosubject = stripslashes($autosubject);
$automessage = stripslashes($automessage);
mail($email,"$autosubject","$automessage","From: $recipientname <$recipientemail>");
}
header("Location: thank-you-sample.php");
?>

mail($email,"$autosubject","$automessage","From: $recipientname <$recipientemail>");
# You've forgotten to include the HTML-header here.. ^

Related

email body not taking carriage returns [duplicate]

Please help me to make code message in line break. i didn't know how to do this please check my code. hope you help me out. thanks alot in advance:-
<?php
if(isset($_POST['submit'])){
$to = "mymail#gmail.com"; // this is your Email address
$from = $_POST['name']; // this is the sender's Email address
$first_name = $_POST['name'];
$mail=$_POST['email'];
$msg=$_POST['message'];
$phone= $_POST['mob'];
$subject = "contact";
$subject2 = "Copy of your form submission";
$message = "Name:-". $first_name . "Email:-". $mail . "Phone Number:-
".$phone. " Message:-".$msg." " ;
$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to,$subject,$message,$headers);
?>
I want to recieve message like this:-
Name:-loreal
email:- Mymail
phone Number:- 987654321
Message:- Hi
Try using \n in your message as:
$message = " Name:-". $first_name . "\n Email:-". $mail . "\n Phone Number:-
".$phone. "\n Message:-".$msg." " ;
They're escape sequences. \n is a newline and \r is a carriage return. \r is a Carriage Return \n is a Line Feed (or new line)
Mac: \r
Linux/Unix: \n
Windows: \r\n
When you are using html tags in email template then you have to mention content type in headers and you have to include that headers in mail function like this
$headers = 'MIME-Version: 1.0' . "\r\n";$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
mail($to,$subject,$message,$headers);
For HTML mail use proper headers:
<?php
if(isset($_POST['submit'])){
$to = "mymail#gmail.com"; // this is your Email address
$from = $_POST['name']; // this is the sender's Email address
$first_name = $_POST['name'];
$mail=$_POST['email'];
$msg=$_POST['message'];
$phone= $_POST['mob'];
$subject = "contact";
$message = "Name:-". $first_name . "<br/>Email:-". $mail . "<br/>Phone Number:-".$phone. "<br/>Message:-".$msg." " ;
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
mail($to,$subject,$message,$headers);
?>
<?php
if(isset($_POST['submit'])){
$to = "mymail#gmail.com"; // this is your Email address
$from = $_POST['name']; // this is the sender's Email address
$first_name = $_POST['name'];
$mail = $_POST['email'];
$msg = $_POST['message'];
$phone= $_POST['mob'];
$subject = "contact";
$subject2 = "Copy of your form submission";
$message = "Name:-" . $first_name . "\n\n" . "Email:-" . $mail . "\n\n" . "Phone Number:- " .$phone . "\n\n" . " Message:- " . $msg;
$headers = "From:" . $from;
$headers .= " MIME-Version: 1.0\r\n"; #Define MIME Version
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; #Set content type
mail($to,$subject,$message,$headers);
header('Location: thank-you.php');
}
else{
echo 'Your message cannot be sent.';
}
?>

php send mail to client and business

I am struggling with the following.When a user fills in a form looking like this, the inquiry gets sent to us to follow up the lead, but I need to find a way to modify my email script to send a confirmation email to the user aswell
My email script looks like this:
MY QUESTION HOW DO I MODIFY THIS TO SEND A THANK YOU CONFIRMATION TO THE USER
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$name = $_POST['name'];
$email = $_POST['email'];
$mobile = $_POST['mobile'];
$eventType = $_POST['eventType'];
$nrGuests = $_POST['nrGuests'];
$state = $_POST['state'];
$suburb = $_POST['suburb'];
$msg = $_POST['msg'];
$refferal_page = $_POST['page'];
$ip = $_SERVER['REMOTE_ADDR'];
if(!isset($refferal_page)){
$refferal_page="Source Unknown";
}
$to_email = "unknown#yahoo.co.nz"; //Recipient email
//TODO Sanitize input data using PHP filter_var().
$suburb = filter_var($_POST["suburb"], FILTER_SANITIZE_STRING);
$subject = "You Have a New Booking!";
//Add booking INFO here;
$message = "A new Enquiry has been received from http://www.xxxxx.com.au. Please find details below and follow up:";
//email body
$message_body = $message."\r\n\r\n".$name."\r\nEmail : ".$email."\r\nPhone Number : ". $mobile."\r\nEvent Type: ".$eventType."\r\nNumber Guests:".$nrGuests."\r\nState: ".$state."\r\nSuburb:".$suburb."\r\nIP ADDRESS:".$ip."\r\nMessage:".$msg."\r\nReferal Page Source:".$refferal_page;
//proceed with PHP email.
$headers = 'From: '.$name.'' . "\r\n" .
'Reply-To: '.$email.'' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$send_mail = mail($to_email, $subject, $message_body, $headers);
if($send_mail)
{
echo '<h1 class="page-header">Enquiry Successfully submitted</h1>';
}
else if(!$send_mail){
echo'<h1 class="page-header" style="color:RED">OOPS...SOMETHING WENT WRONG, PLEASE TRY AGAIN!</h1>';
}
}//server request method
else{
echo'<h1 style="color:red">SUBMIT A FORM PLEASE!</h1>';
}
?>
EMAIL THAT COMES TO US
A new Inqury has been received from www.xxxx.com.au. Please find details below and follow up:
FROM: Ryan XXX
Email : aass#testms.com
Phone Number : 334533
Event Type: Aniversary
Nr Guests: 34
State: Melbourne
Suburb: XYZ
IP ADDR: 162.111.255.111
MSG: this is a test. please disregard
Referal Page Source:aniversary
Obviously I dont want user to see this I just want to add something like "Thank you we will get back to you soon"
Any idea how I can modify the above script for us to get inquiry form but also for user to get an confirmation email?
Any help greatly appreciated
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$name = $_POST['name'];
$email = $_POST['email'];
$mobile = $_POST['mobile'];
$eventType = $_POST['eventType'];
$nrGuests = $_POST['nrGuests'];
$state = $_POST['state'];
$suburb = $_POST['suburb'];
$msg = $_POST['msg'];
$refferal_page = $_POST['page'];
$ip = $_SERVER['REMOTE_ADDR'];
if(!isset($refferal_page)){
$refferal_page="Source Unknown";
}
$to_email = "unknown#yahoo.co.nz"; //Recipient email
//TODO Sanitize input data using PHP filter_var().
$suburb = filter_var($_POST["suburb"], FILTER_SANITIZE_STRING);
$subject = "You Have a New Booking!";
//Add booking INFO here;
$message = "A new Enquiry has been received from http://www.xxxxx.com.au. Please find details below and follow up:";
//email body
$message_body = $message."\r\n\r\n".$name."\r\nEmail : ".$email."\r\nPhone Number : ". $mobile."\r\nEvent Type: ".$eventType."\r\nNumber Guests:".$nrGuests."\r\nState: ".$state."\r\nSuburb:".$suburb."\r\nIP ADDRESS:".$ip."\r\nMessage:".$msg."\r\nReferal Page Source:".$refferal_page;
//proceed with PHP email.
$headers = 'From: '.$name.'' . "\r\n" .
'Reply-To: '.$email.'' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$send_mail = mail($to_email, $subject, $message_body, $headers);
if($send_mail)
{
echo '<h1 class="page-header">Enquiry Successfully submitted</h1>';
$EmailTo = $email;
$subject = "recipient subject";
$message_body = "Hi ".$name."recipient message";
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: yourname<$youremail>\n";
$send_cust_mail = mail($to_email, $subject, $message_body, $headers);
}
else if(!$send_mail){
echo'<h1 class="page-header" style="color:RED">OOPS...SOMETHING WENT WRONG, PLEASE TRY AGAIN!</h1>';
}
}//server request method
else{
echo'<h1 style="color:red">SUBMIT A FORM PLEASE!</h1>';
}
?>

html email shows html codes on submit AND does not send client to thank_you.php page

Right now email is being sent but email received shows the html codes in body of email, and
thank you page does not launch (says "header cannot be modified...).
I would like client to receive an html email correctly AND show client a thank_you.php page I have already created.
Could you please help with corrections?
<?php
if($_POST["submit"])
{
$webmaster="info#limousinesworld.com";
$subject="Limousines Quote Request";
$subject_client="Thank you for your Request";
$ip = $_SERVER['REMOTE_ADDR'];
$ip2 = $_SERVER["HTTP_X_FORWARDED_FOR"];
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else ;
$headers = 'From: LimousinesWorld' . "\r\n" .
'Reply-To: info#limousinesworld.com' . "\r\n" .
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers = 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 'X-
Mailer: PHP/';
$headers = "From: LimousinesWorld <info#limousinesworld.com>";
$replyemail="info#limousinesworld.com";
$senderClient=$_REQUEST['EMail'];
$Comments1 = $_REQUEST['Comments1'] ;
$Comments2 = $_REQUEST['Comments2'] ;
$Name = $_REQUEST['Name'] ;
$Company = $_REQUEST['Company'] ;
$Telephone = $_REQUEST['Telephone'] ;
$EMail = $_REQUEST['EMail'] ;
$When_need_limo = $_REQUEST ['When_need_limo'] ;
$Country = $_REQUEST['Country'] ;
$mailBody= "
Comments1: $Comments1 \n
Comments2: $Comments2 \n
Name: $Name \n
Company: $Company \n
Country: $Country \n
Telephone: $Telephone \n
EMail: $EMail \n
When_need_limo: $When_need_limo \n";
$mailBody_client= '
<html>
<body>
<h1><strong><span style="font-size:16px;"><span style="font-
family:arial,helvetica,sans-serif;">Thank you for your Limousine Quote
Request on our website.</span></span></strong></h1>
<p><span style="font-size:16px;"><span style="font-
family:arial,helvetica,sans-serif;"><strong>We will get back to you with
very soon with: Prices, Pictures, Equipment and Options.</strong>
</span></span></p>
<p><span style="font-family:arial,helvetica,sans-serif;"><span style="font-
size:16px;"><strong>Best regards,</strong></span></span></p>
<p><span style="font-family:arial,helvetica,sans-serif;"><span style="font-
size:16px;"><strong>LimousinesWorld</strong></span></span></p>
</body>
</html>
';
mail($webmaster, $subject, $mailBody, $headers, $ip);
mail($senderClient, $subject_client, $mailBody_client, $headers);
header("Location: http://limousinesworld.com/thank_you.php");
exit;
}
?>
One thing I that noticed right away is that you are not appending to your $header variable. Your code overwrites the $header variable each time. To fix this, you should do something like this:
$headers .= 'MIME-Version: 1.0' . "\r\n";
Notice the . in front of =
This makes it so that you append to the variable rather than overwrite it.

contact form showing my host address. when i got message

hello i have using a contact form when i get any mail from my client i saw my host name showing in mail from. like when i saw saw before open my mail there showing name who send and from where i saw there showing my host name geologicsdz#host.dramaclassesonline.com.
but in mail everything ok.
so i like to change host name where must be show from his email address
$post = (!empty($_POST)) ? true : false;
$replyto='my#email.com';
if($post)
{
$name = stripslashes($_POST['name']);
$email = trim($_POST['email']);
$business = stripslashes($_POST['business']);
$comments = stripslashes($_POST['comments']);
$phone = stripslashes($_POST['phone']);
$howhear = stripslashes($_POST['howhear']);
$to=$toemail.','.$replyto;
$error = '';
$headers="";
$headers.="Reply-to:$replyto\n";
$headers .= "From: $email\n";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers = "Content-Type: text/html; charset=iso-8859-1\n".$headers;
if(!$error)
{
$messages="<h2>From: $name has contacted Geological Solutions</h2>";
$messages.="<h4>Name: $name </h4>";
$messages.="<h4>Email: $email </h4>";
$messages.="<h4>Phone: $phone </h4>";
$messages.="<h4>How did you hear about us?: $howhear </h4>";
$messages.="<h4> Comments: $comments </h4>";
$mail = mail($to,$name,$messages,$headers);
you were in the correct path but have overwritten your headers. here is the fix for it
$headers="";
$headers.="Reply-to:$replyto\r\n";
$headers .= "From: $email\r\n";
$headers .= 'MIME-Version: 1.0';
$headers = "Content-Type: text/html; charset=iso-8859-1\r\n".$headers;

PHP - Mail Form Content - how to add CC field?

I have used this PHP mail script for a while now and it served me well... I need to ask a few things.
Right now, it just sends an email to me with the information posted.
then it just Echo's back to the user if it was submitted successfully or not.
How can I add a CC field to send the user some direction on what to do next?
thanks
if (isset($_POST['submit'])) {
if (!$_POST['name'] | !$_POST['email'])
{
echo"<div class='error'>Error<br />You did not fill in a required field, please review your form and correct the missing information.</div>";
}
else
{
$name = $_POST['name'];
$email = $_POST['email'];
$email2 = $_POST['email2'];
$legal = $_POST['legal'];
$legal2 = $_POST['legal2'];
$address = $_POST['address'];
$address2 = $_POST['address2'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$phone = $_POST['phone'];
$comments = $_POST['comments'];
$yoursite = "See Me Shine Models";
$youremail = $email;
$subject = "Website Model Form";
$message = "$name would like you to contact them about See Me Shine Models.
Contact PH: $phone
Email: $email
Email2: $email2
Legal: $legal
Legal2: $legal2
Address: $address
Address2: $address2
City: $city
State: $state
Zip: $zip
Phone: $phone
Comments: $comments";
$email3 = "myaddress#me.com";
mail($email3, $subject, $message, "From: $email");
echo"<div class='thankyou'>Thank you for contacting us,<br /> we will respond as soon as we can.</div>";
}
}
You need to specify fourth argument of headers:
$xheaders = "";
$xheaders .= "From: Name-Here. <$email>\n";
$xheaders .= "X-Sender: <$email>\n";
$xheaders .= "X-Mailer: PHP\n"; // mailer
$xheaders .= "X-Priority: 1\n"; //1 Urgent Message, 3 Normal
$xheaders .= "Content-Type:text/html; charset=\"iso-8859-1\"\n";
$xheaders .= "Cc: cc_email#example.com\n";
.................
mail($email3, $subject, $message, $xheaders);
Or see this tutorial:
Send email with CC(Carbon Copy) & BCC(Blind Carbon Copy)

Categories