I have created a contact form and I would like for the details be sent to my inbox once the submit button is clicked. Clicking the submit button opens up a new mail page (see getfreepack.org). I have been advised I need a PHP script. I copied one off the web but no too sure how to use it to my advantage. I would appreciate your help.
$Name= $_REQUEST["Name"];
$Email = $_REQUEST["Email"];
$Phone = $_REQUEST["Phone"];
$JobTitle = $_REQUEST["Jobtitle"];
$KeySkills = $_REQUEST["Keyskills"];
$Attachment = $_REQUEST["Attachment"];
$to = "my email address#mail.com";
$subject = "Contact Form";
$message = "Name: " . $Name $message .= "\Email: " . $Email: $message .= "\n Phone: " . $ Phone;
$message .= "\nSubject: " . $Subject; $message .= "\nCover Letter: " . $CoverLetter;
$message .= "\n Attachment: " . $Attachment; $message .= "\nIP Adress: " . $_SERVER['REMOTE_ADDR'];
$message .= "\nBrowser: " . $_SERVER['HTTP_USER_AGENT'];
$message .= "\n\nMessage: " . $theMessage;
$headers = "From: $theEmail";
$headers .= "\nReply-To: $theEmail";
$sentOk = mail($to,$subject,$message,$headers);
echo "sentOk=" . $sentOk;
A very basic one would be :
<?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.";
?>
If you want to go one step more check out the manual : http://php.net/manual/en/function.mail.php
Cheers
You don't need the php to get a form to send to your email address make the form tag like this:
>>action="mailto:youremailaddress#whatever.com">
Input
Input
Related
Please help me to make code message in line break. i didn't know how to do this please check my code. hope you help me out. thanks alot in advance:-
<?php
if(isset($_POST['submit'])){
$to = "mymail#gmail.com"; // this is your Email address
$from = $_POST['name']; // this is the sender's Email address
$first_name = $_POST['name'];
$mail=$_POST['email'];
$msg=$_POST['message'];
$phone= $_POST['mob'];
$subject = "contact";
$subject2 = "Copy of your form submission";
$message = "Name:-". $first_name . "Email:-". $mail . "Phone Number:-
".$phone. " Message:-".$msg." " ;
$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to,$subject,$message,$headers);
?>
I want to recieve message like this:-
Name:-loreal
email:- Mymail
phone Number:- 987654321
Message:- Hi
Try using \n in your message as:
$message = " Name:-". $first_name . "\n Email:-". $mail . "\n Phone Number:-
".$phone. "\n Message:-".$msg." " ;
They're escape sequences. \n is a newline and \r is a carriage return. \r is a Carriage Return \n is a Line Feed (or new line)
Mac: \r
Linux/Unix: \n
Windows: \r\n
When you are using html tags in email template then you have to mention content type in headers and you have to include that headers in mail function like this
$headers = 'MIME-Version: 1.0' . "\r\n";$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
mail($to,$subject,$message,$headers);
For HTML mail use proper headers:
<?php
if(isset($_POST['submit'])){
$to = "mymail#gmail.com"; // this is your Email address
$from = $_POST['name']; // this is the sender's Email address
$first_name = $_POST['name'];
$mail=$_POST['email'];
$msg=$_POST['message'];
$phone= $_POST['mob'];
$subject = "contact";
$message = "Name:-". $first_name . "<br/>Email:-". $mail . "<br/>Phone Number:-".$phone. "<br/>Message:-".$msg." " ;
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
mail($to,$subject,$message,$headers);
?>
<?php
if(isset($_POST['submit'])){
$to = "mymail#gmail.com"; // this is your Email address
$from = $_POST['name']; // this is the sender's Email address
$first_name = $_POST['name'];
$mail = $_POST['email'];
$msg = $_POST['message'];
$phone= $_POST['mob'];
$subject = "contact";
$subject2 = "Copy of your form submission";
$message = "Name:-" . $first_name . "\n\n" . "Email:-" . $mail . "\n\n" . "Phone Number:- " .$phone . "\n\n" . " Message:- " . $msg;
$headers = "From:" . $from;
$headers .= " MIME-Version: 1.0\r\n"; #Define MIME Version
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; #Set content type
mail($to,$subject,$message,$headers);
header('Location: thank-you.php');
}
else{
echo 'Your message cannot be sent.';
}
?>
I have tried sending email from a basic html form by php mail() function and It has given me false return
Code:
<?php
if(isset($_POST['submit'])){
$title = $_POST['title'];
$name = $_POST['first_name'];
$name1 = $_POST['last_name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$company=$_POST['lead_object'];
$skype= $_POST['skype_id'];
$to = 'himanshu#webkidukan.com';
$subject = 'Advertiser Form Details';
$from = 'ssing648#gmail.com';
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Create email headers
$headers .= 'From: '.$from."\r\n".
'Reply-To: '.$from."\r\n" .
'X-Mailer: PHP/' . phpversion();
// Compose a simple HTML email message
$message = '<html><body>';
$message .= '<h1 style="color:#f40;">Hi Sir</h1>';
$message .= '<p style="color:#080;font-size:18px;">Details of Advertiser Form</p>';
$message .= '<p style="color:#080;font-size:18px;"><?php $title . " " . $name . " " . "?>wrote the following:"<?php . "\n\n" . $name . "\n\n" . $name1 . "\n\n" .$email . "\n\n" .$phone . "\n\n" .$company. "\n\n" .$skype. "\n\n"?> </p>';
$message .= '</body></html>';
$t = mail($to, $from, $message, $headers,$subject);
var_dump($t);exit;
if ($t) {
echo "Mail Sent. Thank you " . $name . " .We will contact you shortly.";
}else{
echo "Failed to send email. Please try again later";
}
echo "<script type='text/javascript'>alert('Thanks for filling out our form! We will look over your message and get back to you soon.')</script>";
echo "<script> window.location.href = 'advertiser.php';</script>";
}
?>
I have this issue in three forms together , hence posting one for the understanding the mistake, that I am doing. Can anyone of you help me with the same.Or should I go for the SMTP mail option.Also I am sending the form details in mail to the user.So also check that the way to send the flyer is right or not.
There are some unwanted PHP tags while appending message. try like this
$message = '<html><body>';
$message .= '<h1 style="color:#f40;">Hi Sir</h1>';
$message .= '<p style="color:#080;font-size:18px;">Details of Advertiser Form</p>';
$message .= '<p style="color:#080;font-size:18px;">'.$title." ".$name." wrote the following:"."\n\n".$name."\n\n".$name1."\n\n".$email."\n\n".$phone."\n\n".$company."\n\n".$skype."\n\n".'</p>';
$message .= '</body></html>';
Please help me to make code message in line break. i didn't know how to do this please check my code. hope you help me out. thanks alot in advance:-
<?php
if(isset($_POST['submit'])){
$to = "mymail#gmail.com"; // this is your Email address
$from = $_POST['name']; // this is the sender's Email address
$first_name = $_POST['name'];
$mail=$_POST['email'];
$msg=$_POST['message'];
$phone= $_POST['mob'];
$subject = "contact";
$subject2 = "Copy of your form submission";
$message = "Name:-". $first_name . "Email:-". $mail . "Phone Number:-
".$phone. " Message:-".$msg." " ;
$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to,$subject,$message,$headers);
?>
I want to recieve message like this:-
Name:-loreal
email:- Mymail
phone Number:- 987654321
Message:- Hi
Try using \n in your message as:
$message = " Name:-". $first_name . "\n Email:-". $mail . "\n Phone Number:-
".$phone. "\n Message:-".$msg." " ;
They're escape sequences. \n is a newline and \r is a carriage return. \r is a Carriage Return \n is a Line Feed (or new line)
Mac: \r
Linux/Unix: \n
Windows: \r\n
When you are using html tags in email template then you have to mention content type in headers and you have to include that headers in mail function like this
$headers = 'MIME-Version: 1.0' . "\r\n";$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
mail($to,$subject,$message,$headers);
For HTML mail use proper headers:
<?php
if(isset($_POST['submit'])){
$to = "mymail#gmail.com"; // this is your Email address
$from = $_POST['name']; // this is the sender's Email address
$first_name = $_POST['name'];
$mail=$_POST['email'];
$msg=$_POST['message'];
$phone= $_POST['mob'];
$subject = "contact";
$message = "Name:-". $first_name . "<br/>Email:-". $mail . "<br/>Phone Number:-".$phone. "<br/>Message:-".$msg." " ;
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
mail($to,$subject,$message,$headers);
?>
<?php
if(isset($_POST['submit'])){
$to = "mymail#gmail.com"; // this is your Email address
$from = $_POST['name']; // this is the sender's Email address
$first_name = $_POST['name'];
$mail = $_POST['email'];
$msg = $_POST['message'];
$phone= $_POST['mob'];
$subject = "contact";
$subject2 = "Copy of your form submission";
$message = "Name:-" . $first_name . "\n\n" . "Email:-" . $mail . "\n\n" . "Phone Number:- " .$phone . "\n\n" . " Message:- " . $msg;
$headers = "From:" . $from;
$headers .= " MIME-Version: 1.0\r\n"; #Define MIME Version
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; #Set content type
mail($to,$subject,$message,$headers);
header('Location: thank-you.php');
}
else{
echo 'Your message cannot be sent.';
}
?>
I probably didn't word the title too well.
My web form is working in every other way except when I receive a submission from the web form, it says the sender is Apache, when I would prefer it to say either the user's name or the name of the site the form has been submitted from. Here is my code:
<?php
if(empty($_POST['submit']))
{
echo "Form is not submitted!";
exit;
}
if(empty($_POST["name"]) ||
empty($_POST["email"]))
{
echo "Please complete required fields";
exit;
}
if(isset($_POST['submit'])){
$to = "ncrbrts#live.com";
$from = $_POST['email'];
$name = $_POST['name'];
$phone = $_POST['phone'];
$subject = "Form Submission";
$subject2 = "Copy of Your Form Submission";
$message = $_POST['comment'] . "\n " . "From:" . " " . $_POST['name'] .
"\n " . "Telephone:" . " " . $_POST['phone'] . "\n " . :Email:" . " " . $_POST
['email'];
$message2 = "Thank you for your enquiry." . "\n " .
"Here is a copy of your enquiry for your records: " . "\n " . $_POST['comment']
. "\n " . "A member of our team will contact you shortly to discuss your
requirements.";
$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to, $subject, $headers, $message);
mail($from, $subject2, $message2, $headers2);
}
header('Location: thank-you.html');
?>
I have attempted to change the from variable to say anything else and then just posting the email address in the user's message so I could at least get the information that way. That broke it somewhat! Any help on this would be much appreciated :)
hi I am Unable to comment so writing in Answer section:
if(empty($_POST['submit']))
{
echo "Form is not submitted!";
exit;
what is this for.?
Im creating a contact form for my website using Actionscript 3.0 with Flash CS6, I have my code written down perfectly but in order to receive my messages towards my email ain't working :( Here is my code
<?php
$emailTo = "myemail#myemail.com";
$name = $_POST["Patrick"];
$emailFrom = $_POST["myemail#myemail.com"];
$message = $_POST["Hello"];
$subject = "From Contact Form";
if(!empty($_POST)) {
$body = "Name: " . $name . "\n\n";
$body .= "Email: " . $emailFrom . "\n\n";
$body .= "Message:\n" . $message;
$body = wordwrap($body, 70);
$header = "From: " . $emailFrom . "\nReply-To: " . $emailFrom. "\n\n";
if(mail($emailTo, $subject, $body, $header)) {
echo("result=Successful");
} else {
echo("result=Unsuccessful");
}
}
?>
Thanks and hope I you guys can help me
I think the problem lies in how you try to retrieve the $_POST variables.
You're code suggests that you post fields with the names Patrick, myemail#myemail.com and Hello. That wouldn't be logical.
So I guess that your code should be something like the following:
$emailTo = "myemail#myemail.com";
$name = $_POST["name"];
$emailFrom = $_POST["emailFrom"];
$message = $_POST["message"];
$subject = "From Contact Form";
Or for testing purposes (just to see if your mail script is working):
$emailTo = "myemail#myemail.com";
$name = "Patrick";
$emailFrom = "myemail#myemail.com";
$message = "Hello";
$subject = "From Contact Form";