-5

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.

Kalaivanan
  • 459
  • 2
  • 8
  • 17
  • 4
    PHP is backend, MySQL is a database. – Daan Jul 23 '15 at 14:18
  • Receiving mail server will score the email base on certain criterias. Some will even check the dns record whether the sending server is the mail server for the domain. Pass the scoring and the email will not go into spam. – frz3993 Jul 23 '15 at 14:24
  • @Kalaivanan could you please share what have you tried so far? I mean some code examples. So that we understand what you are trying to achieve. – alagu Jul 23 '15 at 14:32
  • I am confused about this. Some one says PHP is Frontend and Someone says PHP is Backend. What is right? – Kalaivanan Jul 23 '15 at 14:46
  • @Kalaivanan No confuse. PHP is a language to handle database like MySQL. It is called as backend language. For clear idea, just read PHP documentation or this link, http://www.quora.com/Which-programming-languages-are-front-end-and-which-ones-are-back-end – alagu Jul 23 '15 at 15:02
  • Thanks friend. now i understood. – Kalaivanan Jul 23 '15 at 15:20

4 Answers4

1

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.

Rob W
  • 9,134
  • 1
  • 30
  • 50
1

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

  1. Technical setting.
  2. Email content and design.
  3. Reaction to your bulk emails.

A. Technical Settings

  1. Your email must be in the correct format. To ensure the format email underwent you will have to perform SPF and DKIM checkout.
  2. Use a special header in bulk emails for people to know what you send.
  3. Don't forget to add unsubscribe link in an email and it is easy to see and have adequate size and font color.
  4. A reputation of your IP address and domain must be high.

B. Email Content And Design

  1. Avoid using spam words in your mail such as discount, income, money, check, and many more words.
  2. Links that you used in your emails are extremely important. Never take a link from a suspicious resource. Otherwise, it may be fraud.
  3. Your email must be in the plain text version.

C. Recipients’ reaction to your bulk emails

  1. Every email must contain unsubscribe link for the recipient to unsubscribe but not mark as spam.
  2. Name and address of the sender are familiar to the recipients.
  3. 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.

0

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));
?>
alagu
  • 779
  • 1
  • 5
  • 19
  • Thanks Sir, I will try this. – Kalaivanan Jul 23 '15 at 15:11
  • If the receiver already connect with my email means, then the mail go to inbox? – Kalaivanan Jul 23 '15 at 15:14
  • @Kalaivanan receivers are your users or customers who get the email. This is normal PHP mail function. And all emails will go to inbox. Based on your users, it may go to spam. But you have nothing worry about it as it is not under your control. Do you got it? – alagu Jul 24 '15 at 07:36
  • @alagu you are exposing email addresses of all the customers among them with this approach! Are you aware of this? – Rahul Kumar Dec 26 '20 at 07:48
0

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.

Kalaivanan
  • 459
  • 2
  • 8
  • 17