This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 7 years ago.
I am using PHP mail function to send a mail, But am testing my local sever mail has been sent but my live i cant sent mail. Can you please help me?
$email_message = "<b>Form details below</b> <br/><br/>";
$email_message .= "Name: ".$_POST['name']."<br/>";
$email_message .= "Email: ".$_POST['email']."<br/>";
$email_message .= "Phone: ".$_POST['phone']."<br/>";
$email_message .= "Message: ".$_POST['message']."<br/>";
$CusHeaders = 'MIME-Version: 1.0' . "\r\n";
$CusHeaders .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$CusHeaders .= 'From: <'.$_POST['email'].'>' . "\r\n";
$to = "xxxxxxx#gmail.com";
$subject = "Admin - Our Site! Comment from " ;
if(mail($to,$subject,$email_message,$CusHeaders)) {
echo "Email Has Been Sent .";
} else {
echo "Cannot Send Email ";
}
Why use mail() when you have codeigniter email class.
$this->load->library('email');
$this->email->from('your#example.com', 'Your Name');
$this->email->to('someone#example.com');
$this->email->cc('another#another-example.com');
$this->email->bcc('them#their-example.com');
$this->email->subject('Email Test');
$this->email->message('Testing the email class.');
$this->email->send();
echo $this->email->print_debugger();
Use mandrillapp for sending mail using SMTP, and add credentials for email class.
Try it. It's Working
$email_message = "<b>Form details below</b> <br/><br/>";
$email_message .= "Name: ".$_POST['name']."<br/>";
$email_message .= "Email: ".$_POST['email']."<br/>";
$email_message .= "Phone: ".$_POST['phone']."<br/>";
$email_message .= "Message: ".$_POST['message']."<br/>";
$CusHeaders = 'MIME-Version: 1.0' . "\r\n";
$CusHeaders .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$CusHeaders .= 'From: '.$_POST['email'].'' . "\r\n";
$CusHeaders .= 'Reply-To: '.$_POST['email'].'' . "\r\n";
$CusHeaders .= 'X-Mailer: PHP/' . phpversion();
$to = "xxxxxxx#gmail.com";
$subject = "Admin - Our Site! Comment from " ;
if(mail($to,$subject,$email_message,$CusHeaders)) {
echo "Email Has Been Sent .";
} else {
echo "Cannot Send Email ";
}
Use this as html(test)
<form action="#" method="post">
<input type="text" name="name" placeholder="name" />
<input type="text" name="email" placeholder="email"/>
<input type="text" name="phone" placeholder="phone" />
<input type="text" name="message" placeholder="message"/>
<input type="submit" name="submit"/>
</form>
PHP
if(isset($_POST[submit]))
{
$email_message = "<b>Form details below</b> <br/><br/>";
$email_message .= "Name: ".$_POST['name']."<br/>";
$email_message .= "Email: ".$_POST['email']."<br/>";
$email_message .= "Phone: ".$_POST['phone']."<br/>";
$email_message .= "Message: ".$_POST['message']."<br/>";
$CusHeaders = 'MIME-Version: 1.0' . "\r\n";
$CusHeaders .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$CusHeaders .= 'From: <'.$_POST['email'].'>' . "\r\n";
$to = "p******#gmail.com";
$subject = "Admin - Our Site! Comment from " ;
if(mail($to,$subject,$email_message,$CusHeaders)) {
echo "Email Has Been Sent .";
}
else {
echo "Cannot Send Email ";
}
}
?>
Related
I have a website that has a contact form. And when someone uses it I receive the message. But I would like to set up an autoresponder to inform the person who contacted me that their message has been received etc.
Code:
<?php
$data = json_decode(file_get_contents('admin/data/contact.txt'));
include('includes/header.php');
if(isset($_REQUEST['name'])) {
$to = $settings->email;
$subject = 'Contact from Website';
$headers = "From: " . strip_tags($_REQUEST['email']) . "\r\n";
$headers .= "Reply-To: ". strip_tags($_REQUEST['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 = "Hi, A message from contact form.";
$message .= "<br /><br /><br />Name: ".$_REQUEST['name'];
$message .= "<br />Email: ".$_REQUEST['email'];
$message .= "<br />Subject: ".$_REQUEST['subject'];
$message .= "<br />Message: ".$_REQUEST['message'];
mail($to, $subject, $message, $headers);
$msg = 'Your Message has been sent. Thank You.';
}
$btn = '<input type="submit" style="font-size: 14px; font-style: normal; height: auto; color: #fff; border-radius: 15px; border: none;" class="btn_new" value="SEND" />';
?>
How can I edit this code in order to set this up?
Thank you
....
....
$message .= "<br />Message: ".$_REQUEST['message'];
if(#mail($to, $subject, $message, $headers))
{
echo "Mail Sent Successfully";
//Send autoresponder email to $_REQUEST['email'];
//inform the person who contacted me that their message has been received etc.
}
else
{
echo "Mail Not Sent";
}
Oke, this is a tricky one. (I think).
Do you know when you receive a message and the email has a image on top or on the bottom of the page.
I have been trying to make it but can't figure it out.
I hope you guy's can help me with this problem.
This is what I got so far;
<?php
$to = 'info#gmail.com';
if(isset($_POST['submit']))
{
$name = $_POST['name'];
$gast = $_POST['email'];
$tmpName = $_FILES['attachment']['tmp_name'];
$fileType = $_FILES['attachment']['type'];
$fileName = $_FILES['attachment']['name'];
if(empty($errors))
{
$to = $to;
$from = $gast;
$file = fopen($tmpName,'rb');
$data = fread($file,filesize($tmpName));
fclose($file);
$mimeBoundary = "==Multipart_Boundary_x{$randomVal}x";
$body = "E-mail".
"Name: $name\n".
"Email: $gast \n".
"Content-Type: {$fileType};\n".
"Content-Transfer-Encoding: base64\n\n".
$data;
$headers = "From: $from \r\n";
$headers .= "Email: $gast \r\n";
$headers .= "\nMIME-Version: 1.0\n";
$headers .= "Content-Type: multipart/alternative;\n";
$headers .= " boundary=\"{$mimeBoundary}\"";
$headers .= "img src='http://cache.estivant.nl/image/1399025430_12_banners-bestemmingen-single-1680x460-extra2-06-kos_1399025430.jpg' alt='image'";
$data = chunk_split(base64_encode($data));
mail($to, $body, $headers);
}
}
?>
<html>
<head></head>
<body>
<form method="post" action="">
<label for="name">name</label>
<input type="name" name="name" value="" />
<label for="email">email</label>
<input type="email" name="email" value="" />
<button id="submit" name="submit">send</button>
</form>
</body>
</html>
Simply write a html page with css styles and format your email accordingly and use the html as your email body. This will create an image in the mail
<img src="image.jpg" alt="image"></img>
Please be aware that most (if not all) email clients will block your image from being showed to your receiver as long as you are not in their trusted sender list or contact list.
Of course, your email has to be sent as html
Here is an example of a nicely formatted email with images.
Note image syntax: <img src="http://css-tricks.com/examples/WebsiteChangeRequestForm/images/wcrf-header.png" alt="Website Change Request" />'
$to = 'bob#example.com';
$subject = 'Website Change Request';
$headers = "From: " . strip_tags($_POST['req-email']) . "\r\n";
$headers .= "Reply-To: ". strip_tags($_POST['req-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 .= '<img src="http://css-tricks.com/examples/WebsiteChangeRequestForm/images/wcrf-header.png" alt="Website Change Request" />';
$message .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
$message .= "<tr style='background: #eee;'><td><strong>Name:</strong> </td><td>" . strip_tags($_POST['req-name']) . "</td></tr>";
$message .= "<tr><td><strong>Email:</strong> </td><td>" . strip_tags($_POST['req-email']) . "</td></tr>";
$message .= "<tr><td><strong>Type of Change:</strong> </td><td>" . strip_tags($_POST['typeOfChange']) . "</td></tr>";
$message .= "<tr><td><strong>Urgency:</strong> </td><td>" . strip_tags($_POST['urgency']) . "</td></tr>";
$message .= "<tr><td><strong>URL To Change (main):</strong> </td><td>" . $_POST['URL-main'] . "</td></tr>";
$addURLS = $_POST['addURLS'];
if (($addURLS) != '') {
$message .= "<tr><td><strong>URL To Change (additional):</strong> </td><td>" . strip_tags($addURLS) . "</td></tr>";
}
$curText = htmlentities($_POST['curText']);
if (($curText) != '') {
$message .= "<tr><td><strong>CURRENT Content:</strong> </td><td>" . $curText . "</td></tr>";
}
$message .= "<tr><td><strong>NEW Content:</strong> </td><td>" . htmlentities($_POST['newText']) . "</td></tr>";
$message .= "</table>";
$message .= "</body></html>";
mail($to,$subject,$message,$headers);
Code source and full explanation: http://css-tricks.com/sending-nice-html-email-with-php/
In this code i can't able to print the echo statement how can i able to know whether this code is sending mail or not. I'm a web designer not developer. if the echo statement is working means i can undestand that the code is working properly.
if(isset($_REQUEST['email']))
{
echo "dfsdkf";
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "info#ltnts.com";
$email_subject = "Enquiry Details From ltnt.in";
$customer_name=$_REQUEST['fullname'];
$organisation=$_REQUEST['cmp_name'];
$phone_num=$_REQUEST['contact'];
$email=$_REQUEST['logo_emailid'];
$country=$_REQUEST['country'];
$state=$_REQUEST['state'];
$city=$_REQUEST['logo_city'];
$zipcode=$_REQUEST['logo_zipcode'];
$project_type=$_REQUEST['market_type'];
$website_url=$_REQUEST['logo_name'];
$website_purpose=$_REQUEST['business_desc'];
$website_keyword=$_REQUEST['web_keyword'];
$Competitors=$_REQUEST['targent_aud'];
$sample_websites=$_REQUEST['targent_aud1'];
$no_of_updation=$_REQUEST['updation'];
$required_pages=$_REQUEST['checkbox'];
$additional_page=$_REQUEST['addition_page'];
$other_details=$_REQUEST['other_d'];
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Customer Name: ".clean_string($customer_name)."\n";
$email_message .= "organisation: ".clean_string($organisation)."\n";
$email_message .= "phone_num: ".clean_string($phone_num)."\n";
$email_message .= "Email ID: ".clean_string($email)."\n";
$email_message .= "Country: ".clean_string($country)."\n";
$email_message .= "state: ".clean_string($state)."\n";
$email_message .= "city: ".clean_string($city)."\n";
$email_message .= "zipcode: ".clean_string($zipcode)."\n";
$email_message .= "project_type: ".clean_string($project_type)."\n";
$email_message .= "website_url: ".clean_string($website_url)."\n";
$email_message .= "website_purpose: ".clean_string($website_purpose)."\n";
$email_message .= "website_keyword ID: ".clean_string($website_keyword)."\n";
$email_message .= "Competitors: ".clean_string($Competitors)."\n";
$email_message .= "sample_websites: ".clean_string($sample_websites)."\n";
$email_message .= "no_of_updation: ".clean_string($no_of_updation)."\n";
//$email_message .= "required_pages: ".clean_string($required_pages)."\n";
$email_message .= "additional_page: ".clean_string($additional_page)."\n";
$email_message .= "other_details: ".clean_string($other_details)."\n";
$newsletter = $_POST['checkbox'];
if ($newsletter != 'Yes')
{
$newsletter = 'No';
}
$email_message .="Selected:".clean_string($newsletter)."\n";
// create email headers
$headers = 'From: '.$email."\r\n".
'Reply-To: '.$email_to."\r\n" .
'X-Mailer: PHP/' . phpversion();
#mail($email_to, $email_subject, $email_message, $headers);
}
else
{
echo "dfjdhfjshfjz";
}
?>
<input name="checkbox[] "type="checkbox" name="page_Home" value="Home" id="pageHome" onChange="toggleVisibility('home');" /><label for="pageHome"> Home</label><img id="home" src="images/icon-tick.png" style="visibility:hidden"/><br/>
<input name="checkbox[]" value="About_us" id="page_Aboutus" type="checkbox" onChange="toggleVisibility('aboutus');"><label for="page_Aboutus"> About Us</label><img id="aboutus" src="images/icon-tick.png" style="visibility:hidden" /><br/>
<input name="checkbox[]" value="Services" id="pageServices" type="checkbox" onChange="toggleVisibility('services');"><label for="pageServices"> Services</label><img id="services" src="images/icon-tick.png" style="visibility:hidden" /><br/>
<input name="checkbox[]" value="Products" id="pageProducts" type="checkbox" onChange="toggleVisibility('products');"><label for="pageProducts"> Products</label><img id="products" src="images/icon-tick.png" style="visibility:hidden"/><br/>
<input name="checkbox[]" value="Enquiry" id="pageEnquiry" type="checkbox" onChange="toggleVisibility('enquiry');"><label for="pageEnquiry"> Enquiry</label><img id="enquiry" src="images/icon-tick.png" style="visibility:hidden"/><br/>
<input name="checkbox[]" value="Contact_us" id="pageContact" type="checkbox" onChange="toggleVisibility('Contact');"><label for="pageContact">Contact Us</label><img id="Contact" src="images/icon-tick.png" style="visibility:hidden" /><br/>
First check if $_REQUEST['email'] is set and in order to know if code is sending mail or not
You can use error_get_last(), when mail() returns false.
With print_r(error_get_last()) you get proper error
mail() returns TRUE if the mail was successfully accepted for delivery, FALSE otherwise.
It is important to note that just because the mail was accepted for delivery, it does not mean the mail will reach the destination.
use #mail to suppress warnings
Use
if( #mail($email_to, $email_subject, $email_message, $headers) ) {
echo 'mail send';
} else {
print_r(error_get_last());
}
echo '<div id="email">
<form action="#" method="POST">
<label>E-mailadres:</label>
<p><input type="text" name="mail1" value="me#me.nl"> </p>
<input type="submit" name="submitemail">
</form>
</div>';
$to = 'MY#MAIL.COM';
$lala = $_POST['mail1'];
// subject
$subject = 'Subject';
// message
$message = $selected . $totaal .'';
// 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";
$headers .= 'From: ' . $lala . ' <' . $lala . '>';
// Mail it
mail($to, $subject, $message, $headers);
Sending the email is working fine, it just wont let catch the inserted email.
I can't get the value of <input .... name="mail1"> (me#me.nl) into the "FROM:" section.
What do i wrong OR what is the thing that i don't do in this case ?
Whenever using $headers .= 'From: Birthday Reminder <birthday#example.com>' . "\r\n"; it works perfectly.
Try
echo '<div id="email">
<form action="a.php" method="POST">
<label>E-mailadres:</label>
<p><input type="text" name="mail1" value="me#me.nl"> </p>
<input type="submit" name="submitemail">
</form>
</div>';
if (isset($_POST['submitemail'])) {
$to = 'MY#MAIL.COM';
$lala = $_POST['mail1'];
// subject
$subject = 'Subject';
// message
$message = $selected . $totaal . '';
// 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";
$headers .= 'From: ' . $lala . ' <' . $lala . '>';
// Mail it
mail($to, $subject, $message, $headers);
}
the a.php is the name of ur php file
I have made a form for registration by php .The form has submitter email address field.I want that after form submission , form content will send to both form submitter and admin via submitter email address and admin email address. Submitter email address will get from submitter email address field.Admin email address is fixed .
For Submitter
headers= "from : no-reply#eschool.com"
messagebody same as it is
For admin
headers=" from :$email"
messagebody same as it is
I tried to do this:
Html code:
<form action="action.php" method="post">
<table>
<tr>
<td>Name</td>
<td>:</td>
<td><input type="text" name="name" width="400" /></td>
</tr>
<tr>
<td>Address</td>
<td>:</td>
<td><input type="text" name="address" width="400" /></td>
</tr>
<tr>
<td>Email</td>
<td>:</td>
<td><input type="text" name="email" width="400" /></td>
</tr>
<tr>
<td>Password</td>
<td rowspan="2"> </td>
<td>
<p><input type="text" name="pass" width="400" /></p>
<p> </p>
</td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="insert" value="Insert" /></td>
</tr>
</table>
<input type="submit" value="submit" />
</form>
action.php
$name = $_POST["name"];
$address = $_POST["address"];
$email = $_POST["email"];
$password = $_POST['pass'];
$subject = "Thank you for your registration.";
$admin = "info#editor.com";
$to = $email . "," . $admin;
$email_message .= "Name: ". $name."\n";
$email_message .= "Address: ".$address."\n";
$email_message .= "Email: ".$email."\n";
$email_message .= "password: ".$password."\n";
$headers = "MIME-Version: 1.0" . "\n";
$headers .= "Content-type:text/plain;charset=UTF-8;" . "\n";
$headers .= "content-Transfer-encoding: 8bit" ."\n";
$headers .= "From: no-reply#eschool.com ". "\n";
mail($to, $subject, $email_message, $headers);
Thanks
Your code is perfect, what is your are facing problem, plz write your problem.
Make following change in action.php for your convenience :
<?php
$name = $_POST["name"];
$address = $_POST["address"];
$email = $_POST["email"];
$password = $_POST['pass'];
$subject = "Thank you for your registration.";
$admin = "info#editor.com";
//$to = $email $admin;
$email_message = '';
$email_message .= "Name: ". $name."\n";
$email_message .= "Address: ".$address."\n";
$email_message .= "Email: ".$email."\n";
$email_message .= "password: ".$password."\n";
$headers1 = 'MIME-Version: 1.0' . "\r\n";
$headers1 .= 'Content-type: text/plain; charset=UTF-8' . "\r\n";
$headers1 .= "From: no-reply#eschool.com ". "\n";
$headers2 = 'MIME-Version: 1.0' . "\r\n";
$headers2 .= 'Content-type: text/plain; charset=UTF-8' . "\r\n";
$headers2 .= "From: ". $email . "\n";
if(#mail( $email, $subject, $email_message , $headers1 )) {
#mail( $admin, $subject, $email_message , $headers2 )
echo "Mail Sent.";
} else {
echo "Mail Not Sent.";
}
?>
You can simply make two different versions of your headers and execute mail(...) twice:
<?php
$name = $_POST["name"];
$address = $_POST["address"];
$email = $_POST["email"];
$password = $_POST['pass'];
$subject = "Thank you for your registration.";
$admin = "info#editor.com";
$email_message = "Name: ".$name."\n";
$email_message .= "Address: ".$address."\n";
$email_message .= "Email: ".$email."\n";
$email_message .= "password: ".$password."\n";
$headers = "MIME-Version: 1.0\n";
$headers .= "Content-type:text/plain;charset=UTF-8;\n";
$headers .= "content-Transfer-encoding: 8bit\n";
$poster_headers = $headers . "From: no-reply#eschool.com\n";
$admin_headers = $headers . "From: ".$email."\n";
mail( $admin, $subject, $email_message, $admin_headers );
mail( $email, $subject, $email_message, $poster_headers );
?>