Ok so Ive recently developed a php contact form for party inquiries.
The form sends one request to the website and one confirmation to the person who fills out the form.
In gmail it seems that both emails are being sent properly. However, if you fill out the form with a yahoo email it will send only the confirmation. Not the request. This is obviously problematic. So I am trying to figure out why.
My php is as follows:
$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="msg";
$comfirmcontent="msg";
$fromname="mydomain.com";
$fromemail="info#mydomain.com";
$confirmheader=
'From: "' . $fromname . '" <' . $fromemail . '>' . "\r\n" .
'Reply-To: "' . $fromname . '" <' . $fromemail . '>' . "\r\n" .
'X-Mailer: PHP v' . phpversion();
$recipient = "info#mydomain.com";
$subject = "Contact From Website";
$mailheader = "From: $email";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
mail($email, $confirmsubject, $comfirmcontent, $confirmheader) or die("Error!");
header('Location: party-form-thank-you.html')
So this email isnt sending from yahoo:
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
But this one is:
mail($email, $confirmsubject, $comfirmcontent, $confirmheader) or die("Error!");
I thought it may be because the
'X-Mailer: PHP v' . phpversion();
was defined in the confirmation email so I tried writing this into the $mailheader
$mailheader = "From: $email" . "\r\n" .
'X-Mailer: PHP v' . phpversion();
...Didnt work.
So I am asking you all my coding friends for help as to why.
TIA
#kaiqing
You were correct, since the variables were defined as the same with different name I think yahoo was having a problem,
I rewrote it as this:
$name = $_POST['name'];
$email = $_POST['email'];
$fromname="BOULETTESLARDER.COM";
$recipient = "info#bouletteslarder.com";
$subject = "Contact From Website";
$mailheader = 'From: "' . $name . '" <' . $email . '>' . "\r\n" .
'X-Mailer: PHP v' . phpversion();
$confirmheader=
'From: "' . $fromname . '" <' . $recipient . '>' . "\r\n" .
'Reply-To: "' . $fromname . '" <' . $recipient . '>' . "\r\n" .
'X-Mailer: PHP v' . phpversion();
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
mail($email, $confirmsubject, $comfirmcontent, $confirmheader) or die("Error!");
Now it will submit and send both emails — to the website & to the user — if a user filling out the form has a yahoo address.
Related
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 7 years ago.
I was trying to send mail by php, the function mail returns 1, but i didn't get
the mail in my inbox
if (isset($_POST["firstName"]) == false)
return;
$to = "mymail#mail.com";
$subject = $_POST["subject"];
$message = $_POST["content"];
$headers = 'From: ' . $_POST["email"] . "\r\n" .
'Reply-To: ' . $_POST["email"] . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$from = "From: " . $_POST["firstName"] . " " . $_POST["lastName"] . " <" . $_POST["email"] . ">";
echo mail($to, $subject, $message, $headers);
echo '<script type="text/javascript">alert("sent message succesfully");</script>';
Using PHP's mail() function it's possible. Remember mail function will not work in Local server.
<?php
$to = 'abc#example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: admin#example.com' . "\r\n" .
"CC: somebodyelse#example.com";
mail($to, $subject, $message, $headers);
?>
Reference:
http://php.net/manual/en/function.mail.php
Can anyone suggest corrections in these few line of code. I am very much disturbed that it is not working and time elapsing. Please help me with corrections or suggest a new one.
<?php
$email_to = 'info#khawabnama.com';
$subject = "Contact US";
$name =$_POST['flname'];
$email_from = $_POST['email'];
$message = $_POST['message'];
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
$body = 'Name: ' . $name . "\n\n" . 'Email: ' . $email . "\n\n" . 'Subject: ' . $subject . "\n\n" . 'Message: ' . $message;
$success=#mail($email_to, $subject, $body, $headers);
header('Content-type: application/json');
$status = array(
'type'=>'success',
'message'=>'Email sent!'
);
// $success = #mail($email_to, $subject, $body, 'From: <'.$email_from.'>');
echo json_encode($status);
//header("Location: index.php");
//header('Location: http://www.khawabnama.com/index.php');
//die;
The issue I am having is in the message portion of the email. The email sends just fine, the outline is there but no name email or message is printed from the variable. I can't seem to see what the issue is. Any help is appreciated.
<?php session_start();
$name=$_POST['name'];
$email=$_POST['email'];
$text=$_POST['text'];
$to= 'noreply#noreply.com';
$subject = 'Request';
$message='Hello, my name is:' . $name . "\r\n" . 'My Email is: ' . $email . "\r\n" . 'My Message is: '. $text;
$headers = 'From: Request' . "\r\n" .
'Reply-To: noreply#noreply.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
echo 'Mail Sent';
?>
From the comment you are passing the data as query string not as payload in the POST. SO change
$name=$_POST['name'];
$email=$_POST['email'];
$text=$_POST['text'];
to
$name=$_GET['name'];
$email=$_GET['email'];
$text=$_GET['text'];
And should work !
You sent form using GET method, data are in $_GET:
<?php
session_start();
$name = $_GET['name']; // here
$email = $_GET['email']; // here
$text = $_GET['text']; // here
$to = 'noreply#noreply.com';
$subject = 'Request';
$message='Hello, my name is:' . $name . "\r\n" . 'My Email is: ' . $email . "\r\n" . 'My Message is: '. $text;
$headers = 'From: Request' . "\r\n" .
'Reply-To: noreply#noreply.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
echo 'Mail Sent';
?>
To use your current script version, just change method attribute in form to post, like <form method=post ...>
complete beginner at PHP and was wanting a little direction for a website I am creating. I want the admin of the website to receive an email with all of the form information aswell as it being stored in the database. The database is storing the information fine, just need an email notification. How is this achieved. My PHP code is:
<?php
session_start();
include('connection.php');
$product = $_POST['product'];
$productcomments = $_POST['productcomments'];
$name = $_POST['name'];
$address = $_POST['address'];
$age = $_POST['age'];
$delivery = $_POST['delivery'];
mysql_query("INSERT INTO orderform(product, productcomments, name, address, age, delivery)VALUES('$product', '$productcomments', '$name','$address', '$age', '$delivery')");
header("location: google.com");
$to = 'j_bussey#live.co.uk';
$subject = 'Order';
$message = 'Product: ' . $product . '<br /> Product Comments: ' . $productcomments . '<br /> ';
$headers = 'From: webmaster#example.com' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
mysql_close($con);
?>
this is the very basic example of mail function. read more about mail() manual here.
$email = $_POST['email'];
$subject = "Email Subject";
$message = "Email Message Body";
mail($email, $subject, $message, "from: admin#yourdomain.com");
PHP has an awesome mail() function. I'm taking this from the documentation page here: http://us2.php.net/manual/en/function.mail.php
<?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);
?>
So since you're already grabbing the variables, you would just edit the $message variable in the code above to look something like this:
$message = 'Product: ' . $product . '<br /> Product Comments: ' . $productcomments . '<br /> ';
etc, etc. If you don't want to assume that they have html emails enabled, you would use \n instead of <br />
Edit:
You also need to change your header('Location: google.com'); to header('Location: http://www.google.com'); or wherever you want to redirect after the email has been sent off.
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,
);