I'm using the following which sends email fine but doesn't set the reply-to address and I can't figure out why.
$name = $_POST['name'];
$email = $_POST['email_addr'];
$phone = $_POST['phone'];
$body = $_POST['body'];
$body = stripslashes($body);
$message = "Email from site.\n\n
From: $name\n
Email: $email\n
Phone: $phone\n\n
Message: $body";
$to = 'darren#mysite.com';
$subject = 'From Site';
$message = $message;
$headers = 'From: ' . $email . "\r\n" .
'Reply-To: ' . $email . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
Am I missing something obvious?
Related
I was trying to put a simple contact form on my site. I used a template I made on a earlier project, but for some reason it doesn't seem to be working?
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$msg = $_POST['msg'];
$name = strip_tags($name);
$email = strip_tags($email);
$msg = strip_tags($msg);
$email_to = "my.email#email.com";
$email_subject = "Uusi yhteydenotto";
$email_message = "Uusi yhteydenotto: ";
$email_message = "\nName:" .$name.;
$email_message = "\nE-mail:" .$email.;
$email_message = "\n\nMessage:" .$msg.;
$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 think this contains all the necessary things for it to work, but it doesn't seem to work?
Keeps on giving me the error 500. The server should be PHP5 -approved so that shouldn't be the problem
should use concatenation operator ., your code should now look like below
$email_message = "Uusi yhteydenotto: ";
$email_message .= "\nName:" . $name;
$email_message .= "\nE-mail:" . $email;
$email_message .= "\n\nMessage:" . $msg;
Try
$name = $_POST['name'];
$email = $_POST['email'];
$msg = $_POST['msg'];
$name = strip_tags($name);
$email = strip_tags($email);
$msg = strip_tags($msg);
$email_to = "my.email#email.com";
$email_subject = "Uusi yhteydenotto";
$email_message = "Uusi yhteydenotto: ";
$email_message .= "\nName:" .$name; /* removed .; */
$email_message .= "\nE-mail:" .$email; /* removed .; */
$email_message .= "\n\nMessage:" .$msg; /* removed .; */
/* change `$email_from` in $headers = 'From: '.$email_from."\r\n". */
$headers = 'From: '.$email."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
#mail($email_to, $email_subject, $email_message, $headers);
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;
}
The following code is sending an email from my website, but the email comes from cgi-mailer#kundenserver.de, how do i change this to the sender's email address, which i have given the variable $email:
<?php
if(isset($_POST['submit'])) {
$msg = 'Name: ' .$_POST['FirstName'] .$_POST['LastName'] ."\n"
.'Email: ' .$_POST['Email'] ."\n"
.'Message: ' .$_POST['Message'];
$email = $_GET['Email'];
mail('me#example.com', 'Message from website', $msg );
header('location: contact-thanks.php');
} else {
header('location: contact.php');
exit(0);
}
?>
Adding the header From: to my mail command seems to allow me to change the email address, but i can't work out how to do it to the variable.
<?php
$to = "someone#example.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "someonelse#example.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>
For more reference
http://php.net/manual/en/function.mail.php
Declare the variable in the headers..
<?php
$to = 'nobody#example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster#example.com' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
Edit:
<?php
if(isset($_POST['submit'])) {
$msg = 'Name: ' .$_POST['FirstName'] .$_POST['LastName'] ."\n"
.'Email: ' .$_POST['Email'] ."\n"
.'Message: ' .$_POST['Message'];
$email = $_GET['Email'];
$headers = 'From: '.$email."\r\n" .
'X-Mailer: PHP/' . phpversion();
mail('me#example.com', 'Message from website', $msg, $headers );
header('location: contact-thanks.php');
} else {
header('location: contact.php');
exit(0);
}
?>
Add this to the header
$headers .= 'From: ' . $from . "\r\n";
$headers .='Reply-To: $from' . "\r\n" ;
mail($to,$subject,$message,$headers);
It should set the sender.
where
$from= "Marie Debra <marie.debra#website.com>;"
$from = $_POST['email'];
$headers = array('Content-Type: text/plain; charset="UTF-8";',
'From: ' . $from,
'Reply-To: ' . $from,
'Return-Path: ' . $from,
);
I am using a simple contact form and script on a website. The only issue I have is that I would like the email of the person filling out the form used as the reply to e-mail address rather than my servers address when I receive their submission. This is so I can simply reply to the contact rather than having to copy and paste their address and start a new reply to e-mail.
Any simple way to do this?
The below is the simple code I am using.
<?php
header('Location: http://XXXXXXXXXXXXXXXXX/contact.html');
$name = $_REQUEST['Person'];
$company = $_REQUEST['company'];
$address = $_REQUEST['address'];
$city = $_REQUEST['city'];
$state = $_REQUEST['state'];
$zip = $_REQUEST['zip'];
$email = $_REQUEST['email'];
$phone = $_REQUEST['phone'];
$subject = $_REQUEST['subject'];
$details = $_REQUEST ['details'];
$byphone = $_REQUEST ['Phonebox'];
$emailbox = $_REQUEST['Emailbox'];
$message = "From $name\n Company $company\n Address $address\n $city $state $zip\n Email $email\n Phone $phone\n Subject $subject\n\n Details $details\n\n Contact by $byphone $emailbox";
mail ("XXXXXXXXX.com", "Customer Inquiry", "$message", "$email");
?>
Check this out: http://php.net/manual/en/function.mail.php
(Example below)
<?php
$to = 'server_owner#example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: i_filled_the_form#example.com' . "\r\n" .
'Reply-To: i_filled_the_form#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
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);