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.