How to send e-mail to multiple recipients without limit - php

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

Related

How to send a simple email using PHP code

I would like to send an email to my gmail account using some simple PHP code. The code below works in terms of execution, however the problem is even thought is says "Message Sent" I am not receiving my email in my gmail account. Please advice
ini_set('SMTP',"smtp.gmail.com");
$to ="example#gmail.com"; // this will be replaced with my actual email
$from ="example#gmail.com"; // this will be replaced with senders email
$message = $_GET['Message'];
$subject = "This is a test";
if(mail($to,$subject,$message,$from))
{
echo "Message Sent";
}
else
{
echo "Message Not Sent";
}
Steps to send a simple email
Go to google
Search for "PHP Mail"
Click the first result
Read, read, keep reading, wait, read it over, read on
Enjoy!
But seriously:
(Examples are taken from PHP.net)
Example 1
Sending a simple email
Using mail() to send a simple email:
<?php
// The message
$message = "Line 1\r\nLine 2\r\nLine 3";
// In case any of our lines are larger than 70 characters, we should use wordwrap()
$message = wordwrap($message, 70, "\r\n");
// Send
mail('caffeinated#example.com', 'My Subject', $message);
?>
Example 2
Sending mail with extra headers.
The addition of basic headers, telling the MUA the From and Reply-To addresses:
<?php
$to = 'nobody#example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster#example.com' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
Use his line of code:
$to ="example#gmail.com"; // this will be replaced with my actual email
$from ="example#gmail.com"; // this will be replaced with senders email
$headers = "From: ".$from."\r\n";
$headers .= "Reply-To: ".$from."\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 = $_GET['Message'];
$subject = "This is a test";
mail($to, $subject, $message, $headers);

PHP send Multiple email not working

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.

Php mail. Can't get email on one address

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.

how to Send Email details notification using php?

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! :)

how to send many emails in one time by php

i want know
how i can send one mail to 200 user
and i want when the email sendt
it appeare send to:user#mail.com
from:my mail
because i think i see many email like that
to:email1#exaple.com;email2#exaple.com;emial3#exaple.com;
ithink this from bbc
i mean i want every user see sent to this email only
You can use the native mail() function, separate the addresses with a comma, and put them all in the blind carbon copy list with additional headers.
$to = "jon#abc.com,sal#example.com";
$subject = "Mini-mass Emailer";
$message = "Hello World";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: Your Name <me#mydomain.com>' . "\r\n";
$headers .= 'Bcc: {$to}' . "\r\n";
mail($to, $subject, $message, $headers);
Or you could iterate over the collection of email addresses and send each message individually:
$emails = array("foo#bar.com","fizz#buzz.com");
foreach ($emails as $email) {
$to = $email;
$subject = "My Subject";
$message = "Hello World";
mail($to, $subject, $message);
}
Send each mail separately to each user. You can write a helper utility function to do this iteratively.
if use mail function
use bcc in header
like this :
$headers .= 'Bcc: 1#example.com,2#example.com.............' . "\r\n";
u can use a class like phpmailer
and use AddBCC() function

Categories