i m using a php form for sending the contact email from my website. the code is ok and working fine on one website but not working in second website. both website having difference server space and hosting. Not showing any error on page
code is below :
<?php
$name = $_REQUEST['rohini_name'] ;
$contact = $_REQUEST['rohini_contact'] ;
$email = $_REQUEST['rohini_email'] ;
$remark = $_REQUEST['rohini_message'] ;
$MailTxt = "Following are Details" . "\r\n" .
"============================" . "\r\n" .
"Name : " . $name . "\r\n" .
"Mobile : " . $contact . "\r\n" .
"Email : " . $email . "\r\n" .
"Remark : " . $remark . "\r\n";
$to = "ballu9868#gmail.com";
$subject = "Enquiry from rohiniseeds.com";
$headers = "From: www.rohiniseeds.com";
mail($to,$subject,$MailTxt,$headers);
?>
Please ask your hosting to make sure that mail funstion is supported.
Try adding an IF statement around the mail($to,$subject,$MailTxt,$headers) function as follows:
if(mail($to,$subject,$MailTxt,$headers)){
echo 'Success!';
} else {
echo 'Error!';
}
If it says Success then you know that it's being sent by the server, and the problem is when it's trying to hit the inbox. If it says error, then the problem related to the server.
Also, please use email#rohiniseeds.com in the from header, which is a valid email address, instead of the URL of the website.
Please try this
$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);
Related
<?php
$path = 'data.txt';
if (isset($_POST['email']) ) {
$fh = fopen($path,"a+");
$string = $_POST['email'].' - '.$_POST['field2'];
fwrite($fh,$string); // Write information to the file
fclose($fh); // Close the file
}
$to = $_POST['email'];
$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);
?>
Can someone tell me what is wrong with this code?
I want that the script to send email to $_POST['email'] that came from a previous html file.
So first,store that email,and after that sent an email to it.
Thank you
Edit: The script store the email with success but the email is not sent.
Thanks again
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.
I implemented this http://www.websitecodetutorials.com/code/jquery-plugins/jquery-ajaxsubmit.php tutorial on my form, and the form works successfully and displays the thank you div on submission. But the problem is I don't receieve any email, seems like PHP mailer is not working.
Please see the code below
<?php
// Insert your email/web addresses and correct paths
$mailto = 'adil#adilsaleem.co.uk' ;
$from = "web#city.com" ;
$formurl = "http://astonstorlin.co.uk/citycoaches3/formmail.php" ;
$errorurl = "http://astonstorlin.co.uk/citycoaches3/error.php" ;
$thankyouurl = "http://astonstorlin.co.uk/citycoaches3/thankyou.php" ;
// Place Your Form info here...
$pickuppoint = ($_POST['pickuppoint']);
$destination = ($_POST['destination']);
// Check If Empty
// Add more Validation/Cleaning here...
// Place your Corresponding info here...
$message =
"Pick Point: $pickuppoint\n\n" .
"Destination: $destination\n\n" .
"noppl: $noppl\n\n"
;
// Leave Alone
mail($mailto, $from, $message,
"From: \"$name\" <$email>" . $headersep . "Reply-To: \"$name\" <$email>" . $headersep );
header( "Location: $thankyouurl" );
exit ;
?>
I think your headers are not working. $headersep is not defined and moreover please follow :
$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);
Example copied from http://php.net/manual/en/function.mail.php you can refer for more reading this link.
If you are on a shared hosting for example, sometimes they require you to use a fifth parameter like additional_parameters.
mail('nobody#example.com', 'the subject', 'the message', null,'-fwebmaster#example.com');
Check example 3 here: http://php.net/manual/en/function.mail.php
Thank you very much for all your help people, much appreciated.
I got the script working by deleting
"From: \"$name\" <$email>" . $headersep . "Reply-To: \"$name\" <$email>" . $headersep );
And the script started working. I have tried using other HTML php mailer but them don't seem to work with this tutorial example for some reason.http://www.websitecodetutorials.com/code/jquery-plugins/jquery-ajaxsubmit.php
I want to send email using PHP when an HTML form is submitted.
I learnt from a tutorial and made this PHP script, but when I check it in my webmail, I only see email address, subject and message, but no name. What do I need to do to get the name to show up?
Form variables:
if (empty($_POST) === false) {
$errors = array();
$name = trim($_POST["name"]);
$email = trim($_POST["email"]);
$subject = trim($_POST["subject"]);
$message = trim($_POST["message"]);
$answerbox = trim($_POST["answerbox"]);
// ... etc (validation)
if (empty($errors) === true) {
$headers = 'From: '.$email. "\r\n" . $name.
'Reply-To: '.$email . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail('mail#example.com',$subject,$message,$headers);
print "<p class='formerrors'>Thank you for your message, I'll get back to you shortly!</p>";
}
The format of your "From" header isn't right. It should be in the following Format:
"From: Sender Name <sender#domain.com>"
So your $headers assignment should read:
$headers = 'From: '.$name.' <'.$email. ">\r\n" .
'Reply-To: '.$email . "\r\n" .
'X-Mailer: PHP/' . phpversion();
You should modify your $headers variable as:
$headers = 'From: ' .$name. ' <' .$email. '>' . "\r\n" .
'Reply-To: '.$email . "\r\n" .
'X-Mailer: PHP/' . phpversion();
Please read more about mail function on php.net over here: http://php.net/manual/en/ref.mail.php
Moreover maybe PHPMailer, see https://github.com/PHPMailer/PHPMailer is interesting for you to enrich your mails.