I need to know what is best method to send multiple emails using php. It should not be stored in spam and also should send fast.
I already tried normal mail function in PHP. But it is not working well. Also tried using mail function within loop. Only few mails sent and some of them reached under spam folder.
My project is running at live server. And I am using free hosting service.
My Code:
<?php
include "initialize.php";
if($source_url!='http://kalaivanan.byethost18.com/uadmin/send_result.php')
{
echo "Access Denied";
}
else
{
$id=$_GET['id'];
$get_sem_period1=mysqli_query($con, "SELECT * FROM sem_period where id='$id' ");
$get_sem_period=mysqli_fetch_array($get_sem_period1);
$sem_period=$get_sem_period['sem_period'];
$rrr=mysqli_query($con, "SELECT * FROM results where sem_period='$sem_period' ");
$i=1;
while($row=mysqli_fetch_array($rrr))
{
$get_course=mysqli_query($con, "SELECT course,email FROM student_details where reg_no='$row[reg_no]' ");
$get_course1=mysqli_fetch_array($get_course);
$course_name=$get_course1['course'];
$to=$get_course1['email'];
$get_sub1=mysqli_query($con, "SELECT * from course_details where course_name='$course_name' ");
$get_sub=mysqli_fetch_array($get_sub1);
$sem_no=$row['sem_no'];
$subjects=$get_sub['sem'.$sem_no];
$new_subjects=explode(",",$subjects);
$new_marks=explode(",", $row['sem_mark']);
$echo_subject=null;
for($x=0;$x<sizeof($new_subjects);$x++)
{
if($new_marks[$x]>40)
{
$exam_result="Pass";
}
else
{
$exam_result="Fail";
}
$echo_subject .="<tr><td>".$new_subjects[$x].": ".$new_marks[$x]." - ".$exam_result."</td></tr>";
}
$errors='';
$myemail = 'MYEMAIL';
if( empty($errors))
{
$email_subject = "Enquiry Form: Your Results";
echo "Mail id is: ".$to;
echo $email_body = "<table border='1'>
</br> $sem_period Result Will be Announced: Check Your Marks </br> </br>
<tr>
<td> Register Number: ".$row['reg_no']. "</td>
</tr>
<tr>
<td> Course Name: ".$course_name. "</td>
</tr>
<tr>
<td> Semester: ".$sem_no. "</td>
</tr>
<tr>
<td>MARKS ARE:</td>
</tr>
<tr>
<td> ".$echo_subject." </td>
<td> </td>
</tr>
</table>
";
$headers = "From: $myemail\n";
$headers .= "Reply-To: $myemail";
mail($to,$email_subject,$email_body,$headers);
//redirect to the 'thank you' page
echo "<script>alert('Mail Send Successfully');</script>";
}
$email_address="MYEMAIL";
if (!preg_match(
"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*#[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i",
$email_address))
{
$errors .= "\n Error: Invalid email address";
}
}
}
?>
My Answer:
After 1 year, in my experience I learned that for sending large mails without Spam, we have to find good mail service provider.
You should consider using an email sending service, such as Amazons SES, or other marketing tools such as Emma, Mail chimp, sendgrid, mailjet, mandrill, etc.
Free hosts are very susceptible to getting blocked by email servers due to the very nature of use for spam.
This question is a matter of dispute for all the marketers. No one marketer is immune to be called a spammer. These are three main reasons which influence the email reputation:-
Technical setting.
Email content and design.
Reaction to your bulk emails.
A. Technical Settings
Your email must be in the correct format. To ensure the format email underwent you will have to perform SPF and DKIM checkout.
Use a special header in bulk emails for people to know what you send.
Don't forget to add unsubscribe link in an email and it is easy to see and have adequate size and font color.
A reputation of your IP address and domain must be high.
B. Email Content And Design
Avoid using spam words in your mail such as discount, income, money, check, and many more words.
Links that you used in your emails are extremely important. Never take a link from a suspicious resource. Otherwise, it may be fraud.
Your email must be in the plain text version.
C. Recipients’ reaction to your bulk emails
Every email must contain unsubscribe link for the recipient to unsubscribe but not mark as spam.
Name and address of the sender are familiar to the recipients.
The frequency of email sending:- Don't send emails every day. The optimal frequency is not more than once a week.
If you want to know the complete points on this then click here.
I written first time on this community, I hope this article will help you.
If I understood right, you are trying to send emails to multiple users. If so, then try with array & implode() like this below script to send multiple emails. Avoid spam is how you pass the scoring like frz3993 said in comment. And also based on your hosting service provider, the speed, performance factors, etc., measured.
Look that the formatting of this string must comply with RFC 2822 as per Standard.
<?php
$headers = array();
$headers[] = "MIME-Version: 1.0";
$headers[] = "Content-type: text/plain; charset=iso-8859-1";
$headers[] = "From: Kalaivanan <kalai#domain.com>";
$headers[] = "Bcc: Alagu <alagu#domain2.com>";
$headers[] = "Reply-To: Recipient Name <office#domain3.com>";
$headers[] = "Subject: {$subject}";
$headers[] = "X-Mailer: PHP/".phpversion();
$receivers = array('vanan#gmail.com', 'alagukan#gmail.com', 'mathi#gmail.com',.... );
mail(implode(',', $receivers), $subject, $message, $implode("\r\n", $headers));
?>
After few years, I learned many this regarding sending large emails. But the basic this I got from below link. This may be useful for you.
Related
I'm trying to send a message to the email a user provides in the contact form. The problem is the message never gets sent, but I always arrive at a blank page where my php code is located. Nothing warns me of any error in my code. Can anyone explain why this is happening and offer a solution to the problem?
<form action="site.php" method="POST">
<input
type="text"
class="form"
name="email"
placeholder="Your email address"
/>
<button class="submit" type="submit">Join Waitlist</button>
</form>
<?php
if (isset($_POST["submit"]))
{
$mailTo = $_POST["email"];
$mailFrom = "Dumele";
$message = "https://docs.google.com/forms/d/1lpj2XnKW4HT_qHFfGwpUxcvzPmK2USZ0MGSDP0XCqfg/edit";
$subject = "Welcome to Dumele";
$txt = "Thank you for your interest in Dumele. We're glad to have
you join our network and mission to enhance the technological
innovation of our African diaspora. Below is a link to a survey
we would like you to answer so we can better assist you.\n\n".message;
$headers = "From: ".mailFrom;
(mail($mailTo, $subject, $txt, $headers));
header("Location: index.php?mailsend");
}
?>
First of all make sure you enabled error reporting. You can check another Stackoverflow question and it's answers here about it.
As I see in your code you have syntax errors. You didn't place $ sign before variable names. For example you typed $headers = "From: ".mailFrom; instead of $headers = "From: ".$mailFrom; Let's fix it:
<?php
if (isset($_POST["submit"]))
{
$mailTo = $_POST["email"];
$mailFrom = "Dumele";
$message = "https://docs.google.com/forms/d/1lpj2XnKW4HT_qHFfGwpUxcvzPmK2USZ0MGSDP0XCqfg/edit";
$subject = "Welcome to Dumele";
$txt = "Thank you for your interest in Dumele. We're glad to have
you join our network and mission to enhance the technological
innovation of our African diaspora. Below is a link to a survey
we would like you to answer so we can better assist you.\n\n".$message;
$headers = "From: ".$mailFrom;
(mail($mailTo, $subject, $txt, $headers));
header("Location: index.php?mailsend");
}
Now with the mail() function of PHP; some servers disables mail() function for security purposes. If so; you can use SMTP to securely send your emails. To use SMTP in PHP of course you need additional processes but some free software packages and libraries like PHPMailer or SwiftMailer can help you about it.
This is looking for a form value with the name "submit":
if (isset($_POST["submit"]))
But there's no form element in the HTML with that name. So this will always be false. Give your submit button that name:
<button class="submit" type="submit" name="submit">Join Waitlist</button>
It shouldn't necessarily need a value, it would just default to an empty string. But it needs a name in order for the browser to send anything at all with that key.
As an aside, your mail server may reject the message since this is not really an email address:
$mailFrom = "Dumele";
For completeness... It looks like your PHP variables are also syntactically incorrect. Variable names need to begin with a $. For example, this:
$headers = "From: ".mailFrom;
Should be this:
$headers = "From: ".$mailFrom;
The same error would need to be corrected anywhere you're mis-using variable names.
Use value attribute in button tag. You are testing
if(isset($_post['submit']))
But what is submit? You should use value attribute and give a value submit i.e. Submit
I'm struggling with this issue for months now.
I have a simple website wich has a "Get price quota" php form that interested visitors can use to ask for prices.
The PHP form sends an email to the admin using PHP's "mail".
Everything works fine with Google, Hotmail, etc EXCEPT, I get my email rejected all the time from Yahoo recipients. Every two or three months I have to get my dedicated IP changed and the hosting company to make unblacklisting requests because emails sent back to the customers bu the admin using email accounts on the same server\domain are rejected. Weird or not, not all of them are rejected.
I went through all info and tips I could find about securing my form, checked the logs to see if somehow my domain\website is used for spam, I have DKIM enabled, etc, nothing works, I know Yahoo has bad problems but I wonder if there is another way to send emails from forms, small amounts, max 100 per month.
I'm going to post my php email script below, please tell me if there is something wrong that could cause Yahoo to blacklist my domain or is it just Yahoo.
//Secure The Submitted Data
$quoteFirstName = stripslashes($_POST["quoteFirstName"]);
$quoteLastName = stripslashes($_POST["quoteLastName"]);
$quoteEmail = stripslashes($_POST["quoteEmail"]);
$quoteDetails = stripslashes($_POST["quoteDetails"]);
$quoteProduct = stripslashes($_POST["quoteProduct"]);
$quoteTel = stripslashes($_POST["quoteTel"]);
$mailtolink = '' . $quoteEmail .'';
//Build The Email To The Admin
$to = "orders#mydomain.com";
$subject = "Price quota request";
$theEmail = "$quoteFirstName $quoteLastName <br /> $mailtolink <br /> Telephone $quoteTel <br /> Price quota for <br /> - $quoteProduct.<br /> Additional info: $quoteDetails";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
$headers .= "From: " . $quoteEmail . "\r\n" . "Reply-To: " . $quoteEmail . "\r\n" . "X-Mailer: PHP/" . phpversion();
mail($to, $subject, $theEmail, $headers);
So I am sending an HTML e-mail which is an invitation, and I would want users to click Join! if they would want to join the invitation, but then I have no idea how to retrieve their e-mail addresses. I can only get hits of how many "Yes"es I have got, I can't see which e-mail has actually said yes. How can I get their e-mail address too? beside providing them with a text field asking them to fill it up.
Any thoughts? thanks :)
My cade so far:
<html>
<body>
<form action="myserver.com" method="POST" target="_blank">
<input type="hidden" name="answer" value="yes"/>
<input type="submit" name="submit" value="Join!"/>
</form>
</body>
</html>
For the server side, I am using PHP to retrieve the data. Could anything be done from there? I can't use PHP or JS in my e-mails as far as I know.
Since you mention PHP, why not send the email programmatically?
Assuming you have a working SMTP configuration (see Local SMTP), all email adresses in an array, you could use PHP to send out the emails.
See the examples at the resources for specific headers needed for HTML
<?php
$email_addresses = array('foo#bar.tld', 'no#name.it');
// subject
$subject = 'Invitation';
// message
$message = '
<html>
<body>
<form action="myserver.com" method="POST" target="_blank">
<input type="hidden" name="answer" value="yes"/>
<input type="hidden" name="email" value="%placeholder%" />
<input type="submit" name="submit" value="Join!"/>
</form>
</body>
</html>
';
// To send HTML mail, the Content-type header must be set - general part of the header
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: Invitation <your_email#example.com>' . "\r\n";
// iterate over all email addresses
foreach ($email_addresses as $address)
{
// specific version of header
$header = $headers . 'To: ' . $address . ' . "\r\n";
// specific version of message
$msg = str_replace('%placeholder%', $address, $message);
// Mail it
mail($address, $subject, $msg, $header);
}
?>
As always, there are many ways to rome, so you could also input a link into the mail which has the email address (or some other sort of ID) as GET parameter.
Take special care with encodings (ISO vs UTF).
Also, your webserver will be the sender of the Email, so it might get caught in spamfilters if the address differs from the FROM field.
Getting PHP's mail() function to work can be a bit tricky, but the internet is full of solutions, so good luck!
You would have to put their address in the href url as a parameter. It is the only way to get it back.
I won't bother putting all the PHP mail code in here but when you pass something like this:
$address = "their.email#gmail.com";
$msg = '... click here ...'
mail($address, $subject, $msg, $header);
It will render in the email like this:
click here
When they click it, it will send the parameter to your webpage, where you can access it with $_GET['email']
I've built a mailer form in php that allows me to just type in an email address and it fires an email directly to the address entered, this is to save a stupid amount of time due to the fact that i've got to send thousands. The php is below:
<?php
{
$to = $_POST['contactEmail'];
$subject = "UK Exporters - Buyers of Commercial Vehicles";
$headers = "Content-type:text/html;charset=iso-8859-1";
$message =
"
<html><head></head><body style='font-family: arial;'>
<span style='font-weight: bold;'>To whom it may concern,</span><br /><br />
At UK Exporters, we are buyers of Scanias, Volvos, Mercedes, Renaults, DAFs.<br />
Runners and non-runners.<br />
4 X 2’s, 8 x 4’s, 6 x 2’s.<br /><br />
We need your old stock for export orders. Top prices paid. For export orders. If you have any items that you believe we would be interested in purchasing then please reply and let me know. Thank you for reading this email, we hope to hear from you soon.<br /><br />
Kind regards,<br /><br />
Sam<br />
UK Exporters<br /><br />
<img src='http://uk-exporters.co.uk/emailer/card.jpg' />
</body>
</html>"
;
mail($to, $subject, $message, $headers);
echo "Another bites the dust! :D<br /><a href='http://uk-exporters.co.uk/emailer'>Send another</a>"?>
<?php }
?>
I'm not a php expert, so any help would be appreciated, i've also list the reasons why it's being marked as spam:
Content analysis details: (5.5 points, 5.0 required)
pts rule name description
---- ---------------------- --------------------------------------------------
-0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low
trust
[82.197.130.210 listed in list.dnswl.org]
0.0 HTML_MESSAGE BODY: HTML included in message
1.8 HTML_IMAGE_ONLY_08 BODY: HTML: images with 400-800 bytes of words
1.1 MIME_HTML_ONLY BODY: Message only has text/html MIME parts
1.3 RDNS_NONE Delivered to internal network by a host with no rDNS
2.0 MIME_HEADER_CTYPE_ONLY 'Content-Type' found without required MIME
headers
The email would send perfectly well, until I tried sending an image along with it, any ideas guys?
Your analysis details are clear enough. You need to make your header more suitable to your message, by adding the one below:
#For 'Content-Type' found without required IME headers
$headers .= "MIME-Version: 1.0" . "\r\n";
Also seems you missing FROM Address in header
$headers .= 'From: from#email.com' . "\r\n" .
For more on mail headers do read this.
I am trying to figure out the best way to send an automated email to a customer when we update our database with "frames in" i'm thinking javascript & php but don't really know how to implement as a nobo!?
My HTML Form showing checkbox that needs to fire email (only partially shown due to length)
<form action="<?php echo $editFormAction; ?>" name="form" method="POST">
<input name="frame_in" type="checkbox" id="long_tiny" value="yes" <?php if (!(strcmp($row_Recordset1['frame_in'],"yes"))) {echo "checked=\"checked\"";} ?> />
<input type="hidden" name="MM_update" value="form">
</form>
The php mail script (Not sure if completely correct)
$mailTo = $row_customer['email'];
$subject = 'Your Frames Now in!!';
$cName = $row_Recordset2['cName'];
$jobRef = $row_Recordset2['customer_ref'];
$ourRef = $row_Recordset2['our_ref'];
$jobTotal = $row_recordset2['amount'];
mail($mailTo, $subject,
$cName your job Ref: $jobref is now in
<br>
<h2>Details:</h2>
<p>Our ref: $ourRef<br>
Customer Ref: $jobref<br>
Job total: $jobtotal</p>
);
I really don't know how to tie it all together I'm guessing there would need to be error handling as not every customer has an email (But the error doesn't need to be shown)
$mailTo = $row_customer['email'];
$subject = 'Your Frames Now in!!';
$cName = $row_Recordset2['cName'];
$jobRef = $row_Recordset2['customer_ref'];
$ourRef = $row_Recordset2['our_ref'];
$jobTotal = $row_recordset2['amount'];
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$message = "$cName your job Ref: $jobref is now in
<br>
<h2>Details:</h2>
<p>Our ref: $ourRef<br>
Customer Ref: $jobref<br>
Job total: $jobtotal</p>";
if($_POST['frame_in'] == "yes") {
mail($mailTo, $subject,$message, $headers);
}
This is a very broad question. What you need to do is:
Process the form in $editFormAction
If $_POST['frame_in'] is set, do the following:
Get all customers
Send an email to the ones with an e-mail address
Publish a warning on your site for logged-in users (or in general...) that do not have an email address registered.
No aditional javascript needed.
Where exactly are you stuck?
You could try a database trigger that sends an email. The database itself would be sending out the e-mail, and would not involve php at all. This would also be more inclusive, as it would send an email regardless or who/what changes the field, including changes from PhpMyAdmin, or other webpages/scripts.
http://dev.mysql.com/doc/refman/5.0/en/triggers.html
http://forums.mysql.com/read.php?99,33635,33635#msg-33635
This may be limited depending on your hosting environment. If you are using shared hosting, odds are you cannot utilize triggers for security reasons.