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.
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
In my following code it working fine for one email id but when I changed $to with two email id like $to = "test1#gmail.com,test2#gmail.com" then it not sent email to receptions emails.
$to = "test1#gmail.com";
$subject = "Student details";
$msg = "Body Message here";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
if(mail($to,$subject,$msg,$headers))
{
echo "email sent successfully";
}
Might be this question look like silly but it difficult for me to debug why it is not working for multiple email.
How can I send email notification to my users who gave registration details in my form using php?
I have code which runs perfectly to get emails to me, but now I also want to same details to my users.
I am trying to use "$from" into my array at "$to" but getting no email.
my mail.php
<?php
$subject = "Email Notification";
$message = "Thank you for your email";
$message = "Your Registering details are as follows:";
$message .= "<br><br>";
$message .= "<table border='1'>";
$message .= "<tr><td>Name</td><td>".$_POST['name']."</td></tr>";
$message .= "<tr><td>Email</td><td>".$_POST['email']."</td></tr>";
$message .= "</table>";
$from = $_POST['email'];
$to = array('my_address#example.com', 'my_address2#example.com', $from);
$lp = "notification#example.com";
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=utf-8\r\n";
$headers .= 'from: '.$lp .'' . "\r\n" .
'Reply-To: '.$lp.'' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
foreach($to as $row)
{
mail($row,$subject,$message,$headers);
}
echo "Mail Sent.";
die;
?>
It's pretty common that on shared hosting you need to send an email from an "existing email", at least match the domain. Maybe that's why the emails are not being sent?
So for example, if your domain is "www.my-awesome-domain.com", you can't send email headers
"from: example#example.com"
Instead, make sure to send emails from your domain, and ideally an existing email box, for example:
"from: office#my-awesome-domain.com"
Hope it helps! :)
I'm creating a 'forgot password' page where the user enters their email address and the script finds the password associated to that email, and sends it to the stored email address.
I believe the problem has to do with my SMTP Mailserver. I am using WAMP which doesn't have one so I downloaded one that was free.
This is the php script I'm using:
$id = checkEmail($email);
$record = readMemberRecord($id);
$password = #mysql_result($record,0,'cred');
if($password){
$email_subject = "Email Request";
$email_body = "Your password is ".$password.".";
$header = "NinjaMan";
mail($email, $email_subject, $email_body,$header);
$msg = "Your password has been sent to ".$email.".";
}else{
$msg = "Sorry, the email ".$email." wasn't found.";
}
The $msg outputs properly so I know the code is passing the mail function.
Try sending in a proper "From" in $header.
$emailFrom = "admin#yourdomain.com"; // match this to the domain you are sending email from
$email = "example#example.com";
$subject = "Email Request";
$headers = 'From:' . $emailFrom . "\r\n";
$headers .= "Reply-To: " . $email . "\r\n";
$headers .= "Return-path: " . $email;
$message = "Your password is ".$password.".";
mail($email, $subject, $message, $headers);
See details of the mail() function.
If this doesn't work, try using PHPMailer. You configure it in code, no need to edit php.ini.
I've used it in some projects (v 2.0.4, I see the latest is 5.1) and had no problems.
Try using Google's server to send mails, you can see how to do that here
Try using this
//Email information
$to = "garggarima#gmail.com";
$subject = "Test mail";
$message = "Hello! This is a test email message.";
$from = "support#sltechsoft.com";
$headers = "From:" . $from;
$mail=mail($to,$subject,$message,$headers);
if($mail) {
echo "Thanks for mail";
} else {
echo "Mail not Sent";
}
//Email response
echo "Thank you for contacting us!";
Ive got a contact form that isnt sending but is outputting that the message is sent? Can anybody see a problem?
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$to = "myemail#email.co.uk";
//begin of HTML message
$message = "
From : $name,
Email: $email,
Subject: $subject,
Message: $message ";
//end of message
// To send the HTML mail we need to set the Content-type header.
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: Website Enquiry";
if (isset($_POST['name'])) {
// now lets send the email.
mail($to, $subject, $message, $headers);
header('Location: ' . $_SERVER['HTTP_REFERER'] . '?e=Thankyou, we will be in touch shortly.');
} else {
header('Location: ' . $_SERVER['HTTP_REFERER'] . '?e=There was an error sending your message, Please try again.');
}
?>
The "From" header should have a syntactically correct email address. You also need to check the return value of the "mail" function.
$header .= "From: Website Enquiry <enquiry#website.com>";
PS: Please improve your code formatting.
Try to enter an email at From: in $headers.
Like $headers .= "From: youremail#provider.com" or
$headers .= "From: Website Enquiry <youremail#provider.com>"
And you should change it to
if(mail(...)) {
//success
}
else {
//email failed
}