I want to sent 2 different E-Mails to 2 different persons on 'Send Message' Button. I have few questions regarding this.
Is it possible to send Multiple Emails from same Page.
I have written the following code but its not sending Any Email and returning Error Message in return.
<?php
include 'connect.php';
$subject = $_REQUEST['subject'] ; // Subject of your email
$personal_email= "abc#hotmail.com";
$message .= 'Name: ' . $_REQUEST['name'] . "<br>";
$message .= $_REQUEST['product_type']. "<br>";
$message .= $_REQUEST['message'];
$subject_to_sender= "Confirmation";
$message_to_sender = "Thanks for contacting us, Our representative will contact you shortly.";
$name= mysql_real_escape_string($_REQUEST['name']);
$email= mysql_real_escape_string($_REQUEST['email']);
$message= mysql_real_escape_string($_REQUEST['message']);
$product_type= mysql_real_escape_string($_REQUEST['product_type']);
$address= mysql_real_escape_string($_REQUEST['address']);
if($address== "")
{
$address= "No Address is given.";
}
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= "From: " . $_REQUEST['email'] . "\r\n"; // Sender's E-mail
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
if (#mail($email, $subject_to_sender, $message_to_sender, $headers))
{
mail($personal_email, $subject, $message, $headers);
// Transfer the value 'sent' to ajax function for showing success message.
echo 'sent';
To answer your former question, I can say Yes, its possible to use mail() function multiple times.
For the later question, the opening bracket on last if() statement is not closed. Add } after echo 'sent'; statement.
Related
I want to use php to send email to many e-mail addresses but:
I want to make 30 seconds delay between every sent email
I don't want limit to recipients list (my list is over 500 email) when I run the code it tells my time out after 30+ sent email
this is the code I use so far hope if you can help
<?php
$EmailsDB = file('emails.txt');
$from = "myemail#website.com";
$fromName = "Website Name";
$subject = "Subject";
$header = "MIME-Version: 1.0" . "\r\n";
$header .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$header .= 'From: '.$fromName.'<'.$from.'>' . "\r\n";
$message = file_get_contents("message.html");
foreach ($EmailsDB as $to) {
if(mail($to, $subject, $message, $header)) {echo"E-mail sent successfully to $to <br />";}
else {echo"Sorry, failed while sending!";}
}
?>
Hope to find the answer here,
kind regards
I am trying to send email from localhost XAMPP, I have updated all the required files but still unable to send Email from localhost.
Regards: M.Tahseen ur Rehman.
php.ini
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
sendmail.ini
auth_username=myemail#gmail.com
auth_password=mypassword
After all these update i have created a PHP file mail.php to send mails but its not delivering any Email.
include 'connect.php';
$subject = $_REQUEST['subject'] ; // Subject of your email
$personal_email= "abc#hotmail.com";
$message .= 'Name: ' . $_REQUEST['name'] . "<br>";
$message .= $_REQUEST['product_type']. "<br>";
$message .= $_REQUEST['message'];
$subject_to_sender= "Confirmation";
$message_to_sender = "Thanks for contacting us";
$name= $_REQUEST['name'];
$email= $_REQUEST['email'];
$message= $_REQUEST['message'];
$product_type= $_REQUEST['product_type'];
$address= $_REQUEST['address'];
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= "From: " . $_REQUEST['email'] . "\r\n"; // Sender's E-mail
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
if (#mail($email, $subject_to_sender, $message_to_sender, $headers))
{
mail($personal_email, $subject, $message, $headers);
// Transfer the value 'sent' to ajax function for showing success message.
echo 'sent';
}
On Send Button i also send all the Data into Database, and its successfully inserting data into database.
Kindly guide me.
// Subject of your email
$subject = $_REQUEST['subject'] . ' - Personal website contact form submittion.';
// Recipient's E-mail
$to = 'recipient#domain.com';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Sender's E-mail
$headers .= "From: Contact Form (Domain.com) <no-reply#domain.com>";
$message .= 'Name: ' . $_REQUEST['name'] . "<br>";
$message .= 'Email: ' . $_REQUEST['email'] . "<br>";
$message .= 'Message: ' . $_REQUEST['message'] . "<br>";
if (#mail($to, $subject, $message, $headers)) {
// Transfer the value 'sent' to ajax function for showing success message.
echo 'sent';
} else {
// Transfer the value 'failed' to ajax function for showing error message.
echo 'failed';
}
How do I put reply-to header here?
Reply-to email should be the email that person enters while filling up the form, I don't know PHP can anyone help me out? thanks
<?php
$subject = $_REQUEST['subject'] . ' - Personal website contact form submittion.'; // Subject of your email
$to = 'recipient#domain.com'; //Recipient's E-mail
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: Contact Form (Domain.com) <no-reply#domain.com>\r\n"; // Sender's E-mail
$headers .= "Reply-To: ".$_REQUEST['email']."<". $_REQUEST['email'].">\r\n" .
$message .= 'Name: ' . $_REQUEST['name'] . "<br>";
$message .= 'Email: ' . $_REQUEST['email'] . "<br>";
$message .= 'Message: ' . $_REQUEST['message'] . "<br>";
if (#mail($to, $subject, $message, $headers))
{
// Transfer the value 'sent' to ajax function for showing success message.
echo 'sent';
}
else
{
// Transfer the value 'failed' to ajax function for showing error message.
echo 'failed';
}
?>
I have a problem with my mail in php. I code form to send email. I receive email on gmail but I have other mail address and I can't get email on it.
I checked in spam and there is no email also.
Below is my code.
<?php
$emailErr = "";
$endMessage = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["email"])) {
$emailErr = "Proszę uzupełnić pole e-mail";
}
else if (isset($_REQUEST['email']))
//if "email" is filled out, send email
{
//send email
$namesurname = $_REQUEST['name_surname'] ;
$email = $_REQUEST['email'] ;
$number = $_REQUEST['number'] ;
$subject = $_REQUEST['subject'] ;
$message = $_REQUEST['message'] ;
$message = $subject . ": " . $message . " " . $number . " " . $namesurname . " " . $email;
$subject = "=?UTF-8?B?".base64_encode($subject)."?=";
mail("szafor#szafor.pl", "Zamówienie pomiaru",
$message, "From: formularz#szafortest.pl \r\n"."Content-Type: text/plain; charset=UTF-8\r\n");
$endMessage = "Dziękuję za przesłanie wiadomości.";
}
}
?>
One important thing to consider with sending mail is that you should at least have the return path of the message be an email address that is actually hosted on the server that you are sending from.
You can set the From and the Reply-To address as any address, but the return-path should be set to a valid email address hosted on your server. Let's say that you want the "reply" button to send back to "this_email#wherever.com" but the server you are using hosts email for "mydomain.com". Create an email account on your server, "info#mydomain.com" for example.
$recipient = "sendto#email.com";
$subject = "Test email";
$message = "This is the message.";
$headers .= "From: Your Name Here <any_email#wherever.com>\n\r";
$headers .= "Reply-To: Your Name Here <any_email#wherever.com>\n\r";
$headers .= "Return-Path: Your Name Here <info#mydomain.com>\n\r";
$headers .= "Content-Type: text/plain; charset=UTF-8\r\n";
$headers .="X-Mailer: PHP/" . phpversion() . "\r\n";
$headers .="MIME-Version: 1.0\r\n";
mail($recipient, $subject, $message, $headers);
I have found that the more valid header information that I provide, the more likely the email will be delivered. Right now these headers always work for me, and I have a scheduling program that is sending email to a hundred different email addresses every day. See if that works better for you.
There are two steps first the email i sent to the person who wants the newsletter and the second email needs to be sent to info#dirtytrend.com. The problem is that the email is sent in the first step but the email in the second step is never getting through but the code seems to carry on without any errors.
The code is below
<?php
$name = $_POST["nameofperson"];
$to = $_POST["emailofperson"];
$subject = "Hi!";
$body = "Hi " . $name . ",<br><br>Thank you for subscribing?\n\nWe have logged your email to process your newsletter and you will recieve an email from us confirming your subscription.";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
if (mail($to, $subject, $body, $headers)) {
$body2 = "Name: " . $name . "\n";
$body2 .= "Email: " . $to;
if(mail("info#dirtytrend.com", "Subscription Request", $body2)){
header("Location: http://www.dirtytrend.com/events.html");
}
else{
}
} else {
echo "ERROR: Email not sent please contact the system administrator";
}
?>
In the second mail() you have only 3 parameters and you're missing the 4th one with the headers so maybe it is recognized as spam?