Jump to content

mail not working


mbrown
 Share

Recommended Posts

So when I run the following command on the command line the mail is sent without issue

echo -e "Subject: Test Mail\r\n\r\nThis is a test mail" | msmtp --debug -a gmail mike.a.brown09@gmail.com --file=/etc/.msmtp_php

Nothing is showing up in /var/log/msmtp.log or /var/log/mail.log file

 

 

I now have the following in a file called test.php

 

<?php
if(mail("michaelbrown.tsbod@gmail.com","A Subject Here","Hi there,\nThis email was sent using PHP's mail function."))
print "Email successfully sent";
else
print "An error occured";
?>

The /var/log/msmtp.log file shows the following:

 

Mar 23 23:50:10 host=smtp.gmail.com tls=on auth=on user=michaelbrown.tsbod@gmail.com from=mikeabrown.tanyard@gmail.com recipients=michaelbrown.tsbod@gmail.com mailsize=225 smtpstatus=250 smtpmsg='250 2.0.0 OK 1490327410 l6sm714861qkd.66 - gsmtp' exitcode=EX_OK

 
Mar 23 23:51:48 host=smtp.gmail.com tls=on auth=on user=michaelbrown.tsbod@gmail.com from=mikeabrown.tanyard@gmail.com recipients=michaelbrown.tsbod@gmail.com mailsize=225 smtpstatus=250 smtpmsg='250 2.0.0 OK 1490327508 k62sm740834qkd.21 - gsmtp' exitcode=EX_OK
 

 

 
So both the echo statement and the going to test.php work fine and send the email. 
 
But when I have following code and run mail it does not work:
 
<?php
include_once('include/db-config.php');
        function addmailing($votesmotionid)
        {
                global $db_con;
                $motionArray = array($votesmotionid);
                $userSearch=$db_con->prepare("SELECT * from users where enabled=1;");
                $userSearch->execute();
                foreach ($motionArray as $motionid)
                {
                        while ($row=$userSearch->fetch(PDO::FETCH_ASSOC))
                        {
                                $firstName = $row['first_name'];
                                $lastName = $row['last_name'] ;
                                $name="$firstName $lastName";
                        }

                        $motion=$db_con->prepare ("SELECT * from motions where motion_id = :motionid");
                        $motion->bindParam(':motionid',$motionid);
                        if (!$motion->execute()) var_dump($motion->errorinfo());

                        $body="<html>
                                                <head>
                                                        <title>New Motion Addded</title>
                                                </head>
                                                <body>";
                        $body .= "Dear $name <br /><br />";
                        $body .= "A new electronic vote has been created, please review it as soon as possible. The information
                                        is below.";
                        while ($row=$motion->fetch(PDO::FETCH_ASSOC))
                        {
                                $motionid=$row['motion_id'];
                                $motionname=$row['motion_name'];
                                $dateadded=$row['dateadded'];
                                $motiondesc=$row['motion_description'];
                                $body .= "<br ><br />Motion ID: " . $motionid;
                                $body .= "<br />Motion Name: " . $motionname;
                                $body .= "<br />Date Added: " . $dateadded;
                                $body .= "<br />Motion Text: " . $motiondesc;
                        }//End of while

                        $body .= "</body>
                                        </html>";
                }//end of foreach
                $boardEmail = "";
     $emailSearch=$db_con->prepare("SELECT * FROM users where enabled=1");
                $emailSearch->execute();
                while ($row=$emailSearch->fetch(PDO::FETCH_ASSOC))
                {
                        $boardEmail .= $row['email'] .",";
                }
                $subject = "New Motion " . $motionid;
                echo "Board Email: " . $boardEmail;
                $message = $body;
                $headers = "";
                $headers .= "MIME-Version: 1.0\r\n";
                $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
                $headers .= "To: $boardEmail\r\n";
                $headers .= "From: Tanyard Springs Votes <noreply@tanyardspringshoa.com>\r\n";
                //mailing
                mail($boardEmail,$subject,$message,$headers);
        }//end of function

        addmailing(52);


Any help determining what is the issue would be greatly appreciated.  The code base in the last example is rough code which will be fixed once I have this mail issue resolved.

Edited by mbrown
Link to comment
Share on other sites

I changed to the following code and it seems to work some times.

$headers .= "From: Tanyard Springs Votes <noreply@tanyardspringshoa.com>\r\n";
                //mailing
                if (mail($boardEmail,$subject,$message,$headers))
                        print "Email successfully sent";
                else
                        print "An error occured";
        }//end of function

        addmailing(52);

Edited by mbrown
Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.