I need help with the first $headers line.
I need the from to look like this:
name <email>
actually
$field_name <$field_email>
It should show from email in email client
Personname <person#emailaddress.com
How can I achieve this?
<?php
$field_name = $_POST['cf_name'];
$field_email = $_POST['cf_email'];
$field_message = $_POST['cf_message'];
$field_phone = $_POST['cf_phone'];
$mail_to = 'from#email.com';
$subject = 'Enquiry from Website, From: '.$field_name;
$body_message = 'Enquiry submitted to business, via website contact form.';
$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Telephone Number: '.$field_phone."\n";
$body_message .= 'Message: '.$field_message;
$headers = 'From: '$field_name' <'$field_email'>'"\n";
$headers .= 'Reply-To: '.$field_email.;
$mail_status = mail($mail_to, $subject, $body_message, $headers);
include 'contactendd.php';
if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
window.location = 'thanks.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
window.location = 'thanksfailed.html';
</script>
<?php
}
?>
Thanks very much for your help
This line is the right idea:
$headers = 'From: '$field_name' <'$field_email'>'"\n";
but it should read
$headers = 'From: ' . $field_name . ' <' . $field_email . '>\n';
Just missed the periods to concatenate
Headers should be separated by CRLF "\r\n" -- not just \n.
Related
I made a simple contact form using HTML & PHP and I tested, it works perfectly, but when I wanna write in Kurdish or Arabic language the text not displaying properly in my email it looks like that: ÚÛبÛÙ
<?php
$field_name = $_POST['cf_name'];
$field_mobile = $_POST['cf_mobile'];
$field_service = $_POST['cf_service'];
$field_customer = $_POST['cf_customer'];
$field_message = $_POST['cf_message'];
$mail_to = 'email#email.co';
$subject = 'داواکاری بینینی بەڕێوەبەران';
$body_message = 'From: '.$field_name."\n";
$body_message .= 'mobile: '.$field_mobile."\n";
$body_message .= 'Manager: '.$field_service."\n";
$body_message .= 'Sender: '.$field_customer."\n";
$body_message .= 'Message: '.$field_message;
$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";
$mail_status = mail($mail_to, $subject, $body_message, $headers);
if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Message send successfully :)');
window.location = 'https://#.co/interview';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Failed :( Please call the developer!');
window.location = 'https://#/interview';
</script>
<?php
}
?>
Please try below code:
mail( $mail_to, utf8_decode($subject), utf8_decode($body_message), utf8_decode($headers) );
Good day everyone, this is my first time to post here so pls bear with me. I need your help guys, I'm an artist that knows basic html5/css that's why i'm really not good in php.
Anyway I have a project that has a contact form, I just realized that yahoo mail is not working when I fill up the form online, but gmail's are good. Below is my php code. I've been following this PHP Mail() Contact-us form works fine if entering a Gmail sending address, but not with Yahoo but I really can't do it on my own! A brother needs your help. Thank you.
<?php
$field_name = $_POST['cf_name'];
$field_brand = $_POST['cf_brand'];
$field_category = $_POST['cf_category'];
$field_email = $_POST['cf_email'];
$field_facebook = $_POST['cf_facebook'];
$field_instagram = $_POST['cf_instagram'];
$field_number = $_POST['cf_number'];
$field_message = $_POST['cf_message'];
$mail_to = 'dulcetlifestylehub#gmail.com';
$subject = 'DULCET LIFESTYLE - BECOME FAMILY: '.$field_name;
$body_message = 'From Owner: '.$field_name."\n";
$body_message .= 'Brand Name: '.$field_brand."\n";
$body_message .= 'Brand Category: '.$field_category."\n";
$body_message .= 'Email: '.$field_email."\n";
$body_message .= 'Facebook: '.$field_facebook."\n";
$body_message .= 'Instagram: '.$field_instagram."\n";
$body_message .= 'Number: '.$field_number."\n";
$body_message .= 'Message: '.$field_message;
$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";
$mail_status = mail($mail_to, $subject, $body_message, $headers);
if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Thank you for the message. We will contact you shortly.');
window.location = 'becomefamily.htm';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please, send an email to dulcetlifestylehub#gmail.com');
window.location = 'becomefamily.htm';
</script>
<?php
}
?>
<!-- PHP CONTACT FORM -->
<?php
$look = $_POST['look'];
$design = $_POST['design'];
$old_website = $_POST['old_website'];
$redesign = $_POST['redesign'];
?>
<?php
$field_name = $_POST['user_name'];
$field_email = $_POST['user_email'];
$field_message = $_POST['user_message'];
$mail_to = 'alzirabarretto#gmail.com';
$subject = 'Queries';
$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Message: '.$field_message;
$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";
$mail_status = mail($mail_to, $subject, $body_message, $headers);
if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Thank you for the message.');
window.location = '/website_form.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please, send an email to alzirabarretto#gmail.com');
window.location = '/website_form.html';
</script>
<?php
}
?>
I update the php code. When sending the mail it works fine but i don't understand when I didn't received my mail. I have change the radio value according what you have said. And what about the url which I create the input type? I'm bit little confused how to do in php code.
I think this line is wrong.
$radio = $_POST['look' , 'design', 'old_website' , 'redesign'];
Try capturing them separately like this,
$look = $_POST['look'];
$design = $_POST['design'];
$old_website = $_POST['old_website'];
$redesign = $_POST['redesign'];
And even for radio group LOOK, try changing the corresponding values. Or you will get value as radio_1,radio_2, ...
Im trying to create an 'auto reply' function using PHP. The send email script works perfectly on it's own but I'm struggling to get it working with my submit form script... any help would be much appreciated, thanks.
<?php
$field_subject = $_POST['subject'];
$field_name = $_POST['name'];
$field_email = $_POST['email'];
$field_message = $_POST['message'];
$email_to = 'aaron#aaronstrickland.co.uk';
$email_subject = 'Contact Form Message';
$body_message .= 'Name: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Subject: '.$field_subject."\n";
$body_message .= 'Message: '.$field_message;
$headers = "From: $field_email\r\n";
$headers .= "Reply-To: $field_email\r\n";
$mail_status = mail($email_to, $email_subject, $body_message, $headers);
if ($mail_status) {
$to = '$field_email';
$subject = 'Thanks for contacting me';
$message = 'Thanks for your message, I will get back to you soon!';
$headers = 'From: aaron#aaronstrickland.co.uk' . "\r\n" .
'Reply-To: aaron#aaronstrickland.co.uk' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);?>
Here are a few options to do that:
Header back to the form, at the end of the submit.php, including a parameter so you can show a message on form.php if you like:
header("Location: form.php?send=success");
Header to a special thanks page:
header("Location: thanks.html");
Process the form using javascript. Post the data with a AJAX request and on success, show a success message. (google: link)
Try this
<?php
if($_POST['action'] == 'send_mail'){
$field_subject = $_POST['subject'];
$field_name = $_POST['name'];
$field_email = $_POST['email'];
$field_message = $_POST['message'];
$email_to = 'aaron#aaronstrickland.co.uk';
$email_subject = 'Contact Form Message';
$body_message .= 'Name: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Subject: '.$field_subject."\n";
$body_message .= 'Message: '.$field_message;
$headers = "From: $field_email\r\n";
$headers .= "Reply-To: $field_email\r\n";
$mail_status = mail($email_to, $email_subject, $body_message, $headers);
if ($mail_status) {
$to = '$field_email';
$subject = 'Thanks for contacting me';
$message = 'Thanks for your message, I will get back to you soon!';
$headers = 'From: aaron#aaronstrickland.co.uk' . "\r\n" .
'Reply-To: aaron#aaronstrickland.co.uk' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
}
// Your form code here
?>
You are using this file as external file.
I have a form on my page and the information I submit keeps going to my junk folder within my Hotmail email.
I'm not sure what to do I keep changing the headers but the mail still keeps coming into my junk folder.
The code for the PHP is:
<?php
$boundary = uniqid('np');
$field_name = $_POST['cf_name'];
$field_email = $_POST['cf_email'];
$field_message = $_POST['cf_message'];
$mail_to = 'user#hotmail.co.uk';
$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Message: '.$field_message;
$headers = "MIME-Version: 1.0\r\n";
$headers .= "X-Mailer: PHP's mail() Function\n";
$headers .= "Content-Type: multipart/alternative;boundary=" . $boundary . "\r\n";
$headers .= "Subject: Contact\r\n";
$message = "This is a MIME encoded message.";
$message .= "\r\n\r\n--" . $boundary . "\r\n";
$message .= "Content-type: text/plain;charset=utf-8\r\n\r\n";
$message .= "This is the text/plain version.";
$message .= "\r\n\r\n--" . $boundary . "\r\n";
$message .= "Content-type: text/html;charset=utf-8\r\n\r\n";
$message .= "This is the <b>text/html</b> version.";
$message .= "\r\n\r\n--" . $boundary . "--";
$mail_status = mail($mail_to, $subject, $body_message, $headers);
if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Thank you for the message. I will contact you shortly.');
window.location = 'http://www.user.com';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please, send an email to user#hotmail.co.uk');
window.location = 'url';
</script>
<?php
}
?>
One possible problem is if the smtp server from which you are sending the emails, doesn't match the "from" email.
For example if you fill the from field with "yourmail#gmail.com" and the smtp server is not the gmail's one, this might be marked as spam by some mail providers. Unfortunately, there is nothing you can do about it, besides from sending emails from your own domain, that resolves to your smtp server.