Ok so I am writing a php contact form that will send two emails. One to the webmaster with the info and a similar confirmation email sent to the form submitter.
The problem is with the confirmation email. I am trying to configure the From: header and the Reply-to: but and for some reason catching a hurdle.
Originally I had my php set up as so declaring each header parameter...
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$guests = $_POST['guests'];
$type = $_POST['type'];
$month = $_POST['month'];
$day = $_POST['day'];
$year = $_POST['year'];
$message = $_POST['message'];
$formcontent="THIS IS A FORM SUBMISSION FROM domain.COM... \n \n PARTY INQUIRY \n \n From: $name \n Email: $email \n Phone: $phone \n # of Guests: $guests \n Type: $type \n Date Requested: $month $day, $year \n \n Additional Info: $message";
$comfirmcontent="THIS IS A CONFIRMATION OF YOUR FORM SUBMISSION TO domain.COM... \n \n PARTY INQUIRY \n \n From: $name \n Email: $email \n Phone: $phone \n # of Guests: $guests \n Type: $type \n Date Requested: $month $day, $year \n \n Additional Info: $message \n\n\n If you have any further questions please email info#mydomain.com";
$confirmsubject="Confirmation for your inquiry to mydomain.COM";
$confirmheader="From: mydomain.com" . "\r\n" .
"Reply-To: info#mydomain.com" . "\r\n" .
"X-Mailer: PHP/" . phpversion();
$recipient = "info#domain.com";
$subject = "Party Inquiry from Website";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
mail($email, $confirmsubject, $comfirmcontent, $confirmheader) or die("Error!");
header('Location: party-form-thank-you.html')
This as I understand is the proper way, but I am still having the From: say "mydomain.com#myhostdomain.com as both the senders name and senders email. Which is how it was before I even declared the headers and it was null.
So then I tried an override using
mail($email, $confirmsubject, $comfirmcontent, $confirmheader,'-finfo#mydomain.com') or die("Error!");
Which returned the same results.
So I have resorted to simply using the following, w/o declared headers.
mail($email, $confirmsubject, $comfirmcontent, null,'-finfo#mydomain.com') or die("Error!");
This give me the proper from/reply-to address, but also puts it as the senders name.
So my question is if there is any way to write the headers so the email formulates as such:
Senders Name: myDomain.com
Senders Email: info#mydomain.com
I use an array for my headers, then implode them on "\r\n":
$headers = array();
$headers[] = 'Content-type: text/html; charset="UTF-8";';
$headers[] = 'Date: ' . date('r', $_SERVER['REQUEST_TIME']);
$headers[] = 'Message-ID: <' . $_SERVER['REQUEST_TIME'] . md5($_SERVER['REQUEST_TIME']) . (empty($_SERVER['SERVER_NAME']) ? '' : '#' . $_SERVER['SERVER_NAME']) . '>';
// here is the from and reply-to part:
$headers[] = 'From: "' . $fromName . '" <' . $fromAddress . '>';
$headers[] = 'Reply-To: "' . $replyToName . '" <' . $replyToAddress . '>';
$headers[] = 'X-Mailer: PHP v' . phpversion();
if (!empty($_SERVER['SERVER_ADDR'])) {
$headers[] = 'X-Originating-IP: ' . $_SERVER['SERVER_ADDR'];
}
// Use the implode function to collapse the array into a single string
mail($to, $subject, $message, implode("\r\n", $headers));
Related
This question already has answers here:
i want to use bcc or cc function in this mail function?
(3 answers)
Closed 6 years ago.
How can i add cc and bcc in the following script
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$formcontent=" From: $name \n Phone: $phone \n Call Back: $property_id \n Priority: $priority \n Type: $type \n Message: $message , $proptitle";
$recipient = "myemailid#gmail.com";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!" . " -" . "<a href='#' style='text-decoration:none;color:#ff0099;'> Return Home</a>";
?>
You need to set headers for setting cc and bcc:
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// More headers
$headers .= 'From: My Name <myemail#example.com>'. "\r\n";
//Multiple CC can be added, if we need (comma separated);
$headers .= 'Cc: myboss1#example.com, myboss2#example.com' . "\r\n";
//Multiple BCC, same as CC above;
$headers .= 'Bcc: myboss3#example.com, myboss4#example.com' . "\r\n";
mail($to, $subject, $message, $headers);
$mailheader .= 'Cc: joe#bloggs.com' . "\r\n";
$mailheader .= 'Bcc: john#doe.com' . "\r\n";
As per the PHP documentation here.
http://uk3.php.net/manual/en/function.mail.php
You will extend your $mailheader.
$mailheader = "From: $email \r\n" .
"Bcc: someone#example.com' . "\r\n";
**First off all you have to concat $recipient with cc and Bcc variable use like this**
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$formcontent=" From: $name \n Phone: $phone \n Call Back: $property_id \n Priority: $priority \n Type: $type \n Message: $message , $proptitle";
$recipient = "myemailid#gmail.com";
$recipient. = "CC: cc#gmail.com\r\n";
$recipient .= "BCC: bcc#gmail.com\r\n";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!" . " -" . "<a href='#' style='text-decoration:none;color:#ff0099;'> Return Home</a>";
?>
this is related to contact form. i am trying to send a copy of email to user also.
so i thought to replace the same function so i repeated if(!isset($hasError)) second time and changing $emailTo = $email
and this is not working. i thing the problem might with the headers... can i write 2 different header tags ?
// to me
if(!isset($hasError)) {
$emailTo = 'myemail#website.com';
$subject = 'Submitted message from '.$name;
$sendCopy = trim($_POST['sendCopy']);
$body = "Name: $name \n\nEmail: $email \n\nComments: $comments";
$headers = 'From: ' .' <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
mail($emailTo, $subject, $body, $headers);
$emailSent = true;
}
//User Copy
if(!isset($hasError)) {
$emailTo = '$email';
$subject = 'Thank you for Contacting';
$body = "Here is your copy of email which you have sent us. \n\nName: $name \n\nEmail: $email \n\nComments: $comments \n\n Thank you for your email. we will get back to your soon";
$headers = 'From: ' .' <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
mail($emailTo, $subject, $body, $headers);
$UserEmailSent = true;
}
Hi I asked this question a year ago but couldnt solve it and am now having another go.
link to the original question:
Send email to address from form input
I need to send the form data from my form to the specified address 'diysoakwells#hotmail.com' and also the email address from the form field which is assigned the variable $emaile. As it is the email arrives at diysoakwells#hotmail.com but not the variable address ($emaile). I cant understand why but it is definitely picking up the form data as it has all the details included in the email when I receive it at diysoakwells#hotmail.com. I basically want a copy of the order sent to the user as well as myself.
<?php
include_once("wsp_captcha.php");
if(WSP_CheckImageCode() != "OK") {
header('location:/form-rejected.php');
die();
}
$subject = 'Order Inquiry';
$jcitems = " <p><b>ORDER:</b></p><p> " . $_POST['jcitems']."<p/>" . "<p><b>Total:</b> $" . $_POST['jctotal']."</p>";
$time = date ("h:i A");
$date = date ("l, F jS, Y");
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers .= 'From: inquiry#DIYSoakwells.com' . "\r\n" .
'Reply-To: noreply#diysoakwells.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$name = $_POST['name'];
$phone = $_POST['phone'];
$emaile = $_POST['emaile'];
$textbox = $_POST['textbox'];
$to = "diysoakwells#hotmail.com,$emaile";
$text = "<html><body><p>This form was submitted on Your Web Site on \n $date at\n $time</p><p><b>Message:</b>\n$textbox</p><p><b>Customers Email Address:</b> $emaile</p><p><b>Customers Name:</b> $name </p><p><b>Customers Phone Number:</b> $phone </p></html></body>";
$body = $text . $jcitems;
mail($to, $subject, $body, $headers);
Header('Location: ../form-accepted.php');
?>
Please help if you can I will be monitoring this for the next few days. Open to suggestions/explanations!!!
$to = "diysoakwells#hotmail.com;" . filter_var($emaile, FILTER_VALIDATE_EMAIL);
You may also want to try this....
$to = "diysoakwells#hotmail.com;<" . filter_var($emaile, FILTER_VALIDATE_EMAIL) . ">";
I made simple email in wordpress but it would only send email to the administrator email. I need to find the way to send duplicate email with Thanks to the user.
$emailTo = get_option('tz_email');
if (!isset($emailTo) || ($emailTo == '') ){
$emailTo = get_option('admin_email');
}
$subject = 'I Have A Question to Ask from '.$name;
$body = "Name: $name \n\nEmail: $email \n\nPhone: $phone \n\nComments: $comments";
$headers = 'From: '.$name.' ' . "\r\n" . 'Reply-To: ' . $email;
wp_mail($emailTo, $subject, $body, $headers);
$emailSent = true;
}
Insight is appreciated. Thank you.
looks like you already have the user's email address in $email, right? you used it in the message you showed in the question.
$subject = '(duplicate) I Have A Question to Ask from '.$name;
$body = "This message was sent to the administrator:\n\nName: $name \n\nEmail: $email \n\nPhone: $phone \n\nComments: $comments";
$headers = 'From: '.$name.' ' . "\r\n" . 'Reply-To: ' . $email;
wp_mail($email, $subject, $body, $headers);
Just add:
wp_mail($email, "Thank you for your message", $body, $headers);
I'm using the php mail() function and I'd like to change where the mail is comming form, ie: from the default site email to a specific email address. I'm using Dreamhost as my hosting provider.
I've tried this:
<?php
$name = $_GET['name'];
$email = $_GET['email'];
$comment = $_GET['comment'];
$todayis = date("l, F j, Y, g:i a") ;
$subject = "A message sent on ".$todayis." from ".$name." via the playatics website";
$message = " Message: $comment \r \n From: $name \r \n Reply to: $email";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: Domain Name contact#domain.com' . "\r\n";
mail("somemail#domain.com", $subject, $message);
?>
You are a whisker away from the answer here. You are setting a variable $headers, but you are not using it when calling the mail() function.
<?php
$name = $_GET['name'];
$email = $_GET['email'];
$comment = $_GET['comment'];
$todayis = date("l, F j, Y, g:i a") ;
$subject = "A message sent on ".$todayis." from ".$name." via the playatics website";
$message = " Message: $comment \r \n From: $name \r \n Reply to: $email";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: Domain Name contact#domain.com' . "\r\n";
mail("somemail#domain.com", $subject, $message, $headers);
?>
That should do it.
You need to use your headers I think (see http://php.net/manual/en/function.mail.php)
Not directly an answer to your question, but check out PHPMailer if you plan on doing a fair bit of emailing in PHP. It makes things nice and easy :)