This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 7 years ago.
you can see on the title.
i will post here my code.. i please if i done the code worng please
<?php
$name = $_REQUEST["name"];
$email = $_REQUEST["email"];
$mobile = $_REQUEST["mobile"];
//$msg = $_REQUEST["msg"];
$to = "email#email.com"; // <--- Change email ID here
if (isset($email) && isset($name)) {
$subject = "Cadastro para Pos Graduacao em Lideranca e Gestao Sustentavel";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= "From: <".$email.">\r\n"."Reply-To: ".$email."\r\n" ;
$msg = "From: Email: $email <br/>Mobile: $mobile" ; //<br/>Message: $msg
$mail = mail($to, $subject, $msg, $headers);
if($mail)
{
echo 'success';
}
else
{
echo 'failed';
}
}
?>
well.. this codes works on other projets.. so i dont know what im doing wrong..
if(isset($_REQUEST['email']) && !empty($_REQUEST['email'])) {
$name = $_REQUEST["name"];
$email = $_REQUEST["email"];
$mobile = $_REQUEST["mobile"];
$headers = "From: information <".$email.">\n";
$headers .= 'MIME-Version: 1.0' . "\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\n";
$to='email#email.com';
$subject = 'subjenct';
$message = "<html>
<body>
<p style='font-family:verdana; font-size:12px; margin:30px 0 0 30px; align=center'>
<strong> Information </strong> <br>
<strong>Full Name: </strong> ".$name."<br>
<strong>Email: </strong> ".$email."<br>
<strong>Mobile: </strong> ".$mobile."<br>
</p>
</body>
</html>";
$res= mail( $to, $subject, $message, $headers );
}
if($res)
{
echo 'success';
}
else
{
echo 'failed';
}
Related
i am totally lost with why i am getting this error at this code:
$finalmessage = "
From:$_POST['name']
Email:$_POST['email']
Message:$_POST['message']
";
Here is the entire mail php code below:
<?php
$name = $_POST['name'];
$surname = $_POST['surname'];
$email = $_POST['email'];
$message = $_POST['message'];
$support_address = "info#bkslegal";
$headers = "From: ".$email;
$header2 = "From: ".$support_address;
$finalmessage = "
From:$_POST['name']
Email:$_POST['email']
Message:$_POST['message']
";
if ( $name == "")
{
}
else
{
mail("$support_address","finalmessage",$headers);
$result = "Your message has been sent succesfully!"
mail("$email","Thank you for contacting us!","We will soon be in contact with you!",$header2);
}
?>
I see that you wrote your parameters wrong. You wrote:
mail("$support_address","finalmessage",$headers);
It should be:
mail ($support_address, $subject, $message, $headers);
and remove this line
//mail("$email","Thank you for contacting us!","We will soon be in contact with you!",$header2);
PHP mail SYNTAX is:
mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )
Final code :
<?php
$name = $_POST['name'];
$surname = $_POST['surname'];
$email = $_POST['email'];
$support_address = "info#bkslegal";
if($name == "") {
//show somting error message
}
else
{
$Message = "From:".$name."<br />";
$Message .= "Email:".$email."<br />";
$Message .= "Message:". $_POST['message'];
$to = $support_address;
$subject = "new message";
// 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";
// Additional headers
$headers .= 'To: Name <$to>' . "\r\n";
$headers .= 'From: $name <$email>' . "\r\n";
$headers .= 'Cc: birthdayarchive#example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck#example.com' . "\r\n";
if(mail($to, $subject, $Message, $headers)) {
echo "Your message has been Sent";
} else {
echo "Mesage Error";
}
}
?>
Note : Use any mail library for prevent vulnerable to header injection like PHPMailer
I am trying on the following code but it keeps saying Mail not sent. How do I find the real issue? Code given below:
$full_name = htmlspecialchars(trim($_POST['full_name']));
$email = htmlspecialchars(trim($_POST['email']));
$phone = htmlspecialchars(trim($_POST['phone']));
$message = htmlspecialchars(trim($_POST['message']));
$to = "mail#example.com";
$subject = $full_name . ' is interested to have a business discussion with you';
$headers = "From: " . strip_tags($_POST['email']) . "\r\n";
$headers .= "Reply-To: " . strip_tags($_POST['email']) . "\r\n";
// $headers .= "CC: susan#example.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = '<html><body>';
$message .= '<h3>Full Name: </h3>: ' . $full_name . '<br>';
$message .= '<h3>Phone: </h3>: ' . $phone . '<br>';
$message .= '<h3>Message: </h3>: ' . $message . '<br><br>=======================<br>';
$message .= '<h3>IP Address: </h3>: ' . $ip . '<br>';
$message .= '</body></html>';
if(mail($to, $subject, $message, $headers))
{
echo "Mail Sent Successfully";
}else{
echo " Mail Not Sent";
}
Try this code hope this helpful.
<?php
//print_r($_POST);
//$fname = $_POST['fname'];
//$lname = $_POST['lname'];
//$email = $_POST['email'];
//$message = $_POST['message'];
if(isset($_POST['fname']) && $_POST['fname'] != ''){
$fname = $_POST['fname'];
}
if(isset($_POST['lname']) && $_POST['lname'] != ''){
$lname = $_POST['lname'];//phone number
}
if(isset($_POST['email']) && $_POST['email'] != ''){
$email = $_POST['email'];
}
if(isset($_POST['message']) && $_POST['message'] != ''){
$com = $_POST['message'];
}
$to = 'noreply#noreply.com';
$subject = 'Site Visiter.';
// message
$message = sprintf("Site visiter details: <br>Name:- %s <br> Phone:- %s <br> Email:- %s<br> Message:- %s",$fname,$lname,$email,$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";
// Additional headers
$headers .= 'To: Mary <nb158f#gmail.com>' . "\r\n";
$headers .= 'From: mysite.com <admin#site.com>' . "\r\n";
//$headers .= 'Cc: divakar.k#gmail.com' . "\r\n";
// Mail it
$flag = mail($to, $subject, $message, $headers);
echo '<script>alert("Mail Sent :");</script>';
echo '<script>window.location.href="index.php";</script>';
<?php
if(isset($_POST['submit']))
{
$name = $_POST['name'];
$email = $_POST['email'];
$query = $_POST['message'];
$email_from = $name.'<'.$email.'>';
$to="someone#gmail.com";
$subject="Enquiry!";
$headers .= "From: ".$email_from."\r\n";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n".PHP_EOL;
$message="mail sent";
if(mail($to,$subject,$message,$headers))
{
header("Location:../contact.php?msg=Successful Submission! Thankyou for contacting us.");
}
else
{
header("Location:../contact.php?msg=Error To send Email !");
}
}
?>
<?php
if(isset($_POST['submit']))
{
$name = $_POST['name'];
$email = $_POST['email'];
$query = $_POST['message'];
$email_from = $name."<'.$email.'>"; //Check Properly Here
$to="someone#gmail.com";
$subject="Enquiry!";
$headers .= "From: ".$email_from."\r\n";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n".PHP_EOL;
$message="mail sent";
$SendMail=mail($to,$subject,$message,$headers); //Check Here Too
if($SendMail)
{
header("Location:../contact.php?msg=Successful Submission! Thankyou for contacting us.");
}
else
{
header("Location:../contact.php?msg=Error To send Email !");
}
}
?>
I've recently moved hosts and now with the contact form I have to use SMTP. I have been able with some help get something to work but am unable to retrieve the information I need from the form. The information I am trying to pull is name email phone and message. This is what I have been using
<?php
require "email.php";
$mail = new EMail;
$mail->Username = 'username.co.uk';
$mail->Password = 'mypassword';
$mail->SetFrom("no-reply#mywebsite.co.uk","no-reply#mywebsite.co.uk"); // Name is optional
$mail->AddTo("no-reply#mywebsite.co.uk","no-reply#mywebsite.co.uk"); // Name is optional
$mail->Subject = "Hello World Again!";
$mail->Message = "Hello World!";
//Optional
$mail->ContentType = "text/html"; // Defaults to "text/plain; charset=iso-8859-1"
$mail->Headers['X-SomeHeader'] = 'abcde'; // Set some extra headers if required
$mail->ConnectTimeout = 30; // Socket connect timeout (sec)
$mail->ResponseTimeout = 8; // CMD response timeout (sec)
$success = $mail->Send();
?>
When I test this an email gets sent but of course only the "Hello World" text gets sent as I'm unsure where to put the necessary code to pull the info I need.
Prior to moving hosts and not needing SMTP I was using this script
<?php
//-----------------------------------------------------
//-----------------------------------------------------
$address= "myemail.co.uk";
//-----------------------------------------------------
//-----------------------------------------------------
$name = $_REQUEST["name"];
$email = $_REQUEST["email"];
$phone = $_REQUEST["phone"];
$message_content = $_REQUEST["message"];
$mime_boundary = md5(time());
$headers = "From: $name <$email>\n";
$headers .= "Reply-To: $subject <$email>\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: multipart/alternative; boundary=\"$mime_boundary\"\n";
$message = "-- $mime_boundary\n\n";
$message .= "New email from the Commons website: \n\n\n";
$message .= "Name: $name \n\n";
$message .= "Email: $email \n\n";
$message .= "Phone: $phone \n\n";
$message .= "Message: $message_content \n\n";
$message .= "--$mime_boundary--\n\n";
$mail_sent = mail($address, $subject, $message, $headers);
echo $mail_sent ? "Success, mail sent!" : "Mail failed";
?>
Thanks in advance
Kind Regards
Tim
Did u try as this way???
$message_str = str_replace("[first_name]", $fname, $message_str);
$message_str = str_replace("[last_name]", $lname, $message_str);
$message_str = str_replace("[site_name]", "RMS", $message_str);
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// More headers
$headers .= 'From: <norply#rms.com>' . "\r\n";
$subject = "activate account!";
if (mail("asd#sad.com", $subject, $message_str, $headers)) {
echo"Email successfully sent!";
} else {
echo"Email delivery failed…";
}
Just USe Php Mail function
consider below code
$subject = 'Welcome To demo.com';
$mydata['name'] = 'demo';
$mydata['user_name'] = 'test1';
$mydata['email'] = test#gmail.com;
$mydata['password'] = $password;
$mydata = (object)$mydata;
$message = "<div style='height: 500px; background: none repeat scroll 0% 0% rgb(241, 241, 241); border: 1px solid rgb(6, 106, 117); width: 450px;'>
<div style='width: 100%; background: none repeat scroll 0% 0% rgb(6, 106, 117); height: 80px;'>
<div style='width:150px; height:100px;margin:8px; float:left'>
</div>
</div>
<div style='width:100%;height:360px; margin: auto; float:left; text-align: center;'>
<h2>Hello $mydata->name </h2>
<h3>Here is you login details for Demo</h3>
<br>
<h3>Username: $mydata->user_name</h3>
<h3>Password: $mydata->password</h3>
</div>
<div style='height:30px;padding-top:10px;float:left; width:100%;text-align:center;background:#1d5770;'>
<span style='color:#fff;font-weight:bold'>demo Team</span>
</div>
</div>";
//$message = "<br><br>Username:$mydata->user_name <br><br><br>Password:$mydata->password <br>";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "To: $mydata->name <$mydata->email>" . "\r\n";
$headers .= "From: demo.com <contact#demo.com>" . "\r\n";
mail($mydata->email, $subject, $message, $headers);
for further reference follow these links
http://www.w3schools.com/php/php_ref_mail.asp
http://php.net/manual/en/function.mail.php
I used this however the message I get is that the email failed
<?php
require "email.php";
$mail = new EMail;
$mail->Username = 'myemail.co.uk';
$mail->Password = 'password';
$name = $_REQUEST["name"];
$email = $_REQUEST["email"];
$phone = $_REQUEST["phone"];
$message_content = $_REQUEST["message"];
$mime_boundary = md5(time());
$headers = "From: $name <$email>\n";
$headers .= "Reply-To: $subject <$email>\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: multipart/alternative; boundary=\"$mime_boundary\"\n";
$message = "-- $mime_boundary\n\n";
$message .= "New email from the Commons website: \n\n\n";
$message .= "Name: $name \n\n";
$message .= "Email: $email \n\n";
$message .= "Phone: $phone \n\n";
$message .= "Message: $message_content \n\n";
$message .= "--$mime_boundary--\n\n";
echo $mail_sent ? "Success, mail sent!" : "Mail failed";
?>
I have an html form the links to a PHP email. The form works well, but I am having trouble with the Cc and Bcc not coming through.
Here is the entire code. Please review and help me understand what I am getting wrong on the Cc and Bcc parts in the headers.
Thanks:
<?php
$emailFromName = $_POST['name'];
$emailFrom = $_POST['email'];
$emailFromPhone = $_POST['phone'];
$email9_11 = $_POST['9-10'];
$email10_11 = $_POST['10-11'];
$email11_12 = $_POST['11-12'];
$email12_1 = $_POST['12-1'];
if (empty($emailFromName)) {
echo 'Please enter your name.';
} elseif (!preg_match('/^([A-Z0-9\.\-_]+)#([A-Z0-9\.\-_]+)?([\.]{1})([A-Z]{2,6})$/i', $emailFrom) || empty($emailFrom)) {
echo 'The email address entered is invalid.';
} else {
$emailTo = "main#gmail.com" ;
$subject = "Family History Conference Registration";
if (!empty($emailFrom)) {
$headers = 'From: "' . $emailFromName . '" <' . $emailFrom . '>';
} else {
$headers = 'From: Family History Conference <noreply#domain.org>' . "\r\n";
$headers .= 'Cc: $emailFrom' . "\r\n";
$headers .= 'Bcc: myemail#domain.com' . "\r\n";
}
$body = "From: ".$emailFromName."\n";
$body .= "Email: ".$emailFrom."\n";
$body .= "Phone: ".$emailFromPhone."\n\n";
$body .= "I would like to attend the following classes.\n";
$body .= "9:10 to 10:00: ".$email9_11."\n";
$body .= "10:10 to 11:00: ".$email10_11."\n";
$body .= "11:10 to 12:00: ".$email11_12."\n";
$body .= "12:10 to 1:00: ".$email12_1."\n";
/* Send Email */
if (mail($emailTo, $subject, $body, $headers)) {
echo "<h2>Thank you for Registering</h2>
<h3>You have registered for the following classes</h3>
<p>9:10 to 10:00am: \"$email9_11\" <br />
10:10 to 11:00am: \"$email10_11\"<br />
11:10 to 12:00: \"$email11_12\"<br />
12:10 to 1:00: \"$email12_1\"</p>
<p>We look forward to seeing you October 31, 2010</p>";
} else {
echo 'There was an internal error while sending your email.<br>';
echo 'Please try again later.';
}
}
?>
You're using single quotes
$headers .= 'Cc: $emailFrom' . "\r\n";
PHP won't interpret variables inside single quotes, you must use double quotes
$headers .= "Cc: $emailFrom\r\n";