[email protected] Posted December 7, 2009 Share Posted December 7, 2009 I am trying to take email addresses from my database table and send email to everyone. But it shows that the email is sent but most of them complain the email never received... <?php /*Sening emails to users using script*/ /*Selecting all the users from database*/ require('includes/connection.php'); $userArray = array(); $i = 0; $result = mysql_query("SELECT DISTINCT email_id, email_address FROM submit_emails")or die(mysql_error()); if(!empty($result)) { while($row = mysql_fetch_array($result)) { $userArray['id'][$i] = $row['email_id']; $userArray['email'][$i] = $row['email_address']; $i++; $counter = $i; } } /*Actual html mail*/ for($j=0; $j <= $counter; $j++) { $to_email = $userArray['email'][$j]; $to_id = $userArray['id'][$j]; $subject = 'Learn New Technologies'; $message = '' // This is the message...dont worry abt this! .'<table width="520" border="0">' . '<tr>' . '<td width="514"><img src="http://www.ideatoceo.com/emails/kalima.gif" width="514" height="89" longdesc="http://shetech.ideatoceo.com/registration.php"/></td>' . '</tr>' . '<tr>' . '<td>' .'<table width="512" border="0">' . '<tr>' . '<td width="251"> ' .'<div align="center"><span style="color:#333333" style="font-size:8px">Group of professionals are now ready to train muslims for FREE</span></div>' . '<p> <span style="color:#000033" style="font-weight:bold">PHP</span><br /> <span style="color:#003300" style="font-weight:bold">MySQL</span><br /> <span style="color:#993300" style="font-weight:bold">Web Services</span><span style="color:#000000" style="font-weight:bold"> & more...</span></p>' . '<p align="center" style="color:#990000" style="font-weight:bold"><a href="http://shetech.ideatoceo.com/registration.php" target="_blank">Work on live projects and get trained!</a></p>' . '</td>' . '<td width="251"><img src="http://www.ideatoceo.com/emails/training.gif" width="205" height="204" align="right" longdesc="http://shetech.ideatoceo.com/registration.php"/></td>' . '</tr>' .'</table>' . '</td>' . '</tr>' . '<tr>' . '<td><label><label><img src="http://www.ideatoceo.com/emails/Bottom2.gif" width="514" height="48" longdesc="http://shetech.ideatoceo.com/registration.php"/></label></label></td>' . '</tr>' .'</table>' .'<table>' .'Forward to friends and help them, visit <a href="http://www.ideatoceo.com/islam/emails.php" target="_blank">IdeatoCEO </a><br />' .'<a href="http://www.ideatoceo.com/islam/remails.php" target="_blank">Unsubscribe</a> from the distribution<br />' . '<br />' .'www.ideatoceo.com | XXXXX | Saint Louis | MO | XXXX <br />' .'</table>'; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= "X-Priority: 1 (Higuest)\n"; $headers .= "X-MSMail-Priority: High\n"; $headers .= "Importance: High\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= 'From:[email protected]' . "\r\n"; echo "<table border='1'> <tr> <th>Email Sent to following people</th> </tr>"; echo "<tr>"; echo "<td>" . $to_id . "</td>" . "<td>" . $to_email . "</td>"; echo "</tr>"; mail($to_email, $subject, $message, $headers); echo "</table>"; sleep(1); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/184243-why-mails-are-not-going/ Share on other sites More sharing options...
vinpkl Posted December 7, 2009 Share Posted December 7, 2009 echo $to_email how many addresses does it output vineet Quote Link to comment https://forums.phpfreaks.com/topic/184243-why-mails-are-not-going/#findComment-972686 Share on other sites More sharing options...
[email protected] Posted December 7, 2009 Author Share Posted December 7, 2009 I have echo in *for loop*, so as and when mails are sent it will show me a report $to_id and $to_email in table form. It is showing me all the emails I have in db...but my issue is that people are not receiving emails.... Does anyone see any error ? Quote Link to comment https://forums.phpfreaks.com/topic/184243-why-mails-are-not-going/#findComment-972693 Share on other sites More sharing options...
Deoctor Posted December 7, 2009 Share Posted December 7, 2009 hi ur code is atmost perfect, There is nothing wrong in your code.. so can u check these things with your server. telnet <server ip adress> 25 is this command giving any result like opening up SMTpP or vsftd something.. if yes then ur program should send the mail. or else try sending the mail using an smtp server and port u can use this code /* send mail using an smtp*/ <?php require_once "Mail.php"; $from = "Chaitu <[email protected]>"; $to = "Chaitu <[email protected]>"; $subject = "Hi!"; $body = "Hi,\n\nHow are you?"; $host = "mail.example.com"; $username = "smtp_username"; $password = "smtp_password"; $headers = array ('From' => $from, 'To' => $to, 'Subject' => $subject); $smtp = Mail::factory('smtp', array ('host' => $host, 'auth' => true, 'username' => $username, 'password' => $password)); $mail = $smtp->send($to, $headers, $body); if (PEAR::isError($mail)) { echo("<p>" . $mail->getMessage() . "</p>"); } else { echo("<p>Message successfully sent!</p>"); } ?> it the smtp uses the autentication then try this code /*Sending Mail from PHP Using SMTP Authentication and SSL Encryption - Example */ <?php require_once "Mail.php"; $from = "Chaitu <[email protected]>"; $to = "Chaitu <[email protected]>"; $subject = "Hi!"; $body = "Hi,\n\nHow are you?"; $host = "ssl://mail.example.com"; $port = "465"; $username = "smtp_username"; $password = "smtp_password"; $headers = array ('From' => $from, 'To' => $to, 'Subject' => $subject); $smtp = Mail::factory('smtp', array ('host' => $host, 'port' => $port, 'auth' => true, 'username' => $username, 'password' => $password)); $mail = $smtp->send($to, $headers, $body); if (PEAR::isError($mail)) { echo("<p>" . $mail->getMessage() . "</p>"); } else { echo("<p>Message successfully sent!</p>"); } ?> hope these would help u out.. Quote Link to comment https://forums.phpfreaks.com/topic/184243-why-mails-are-not-going/#findComment-972694 Share on other sites More sharing options...
[email protected] Posted December 8, 2009 Author Share Posted December 8, 2009 Its not that I am not able to send emails. It sometimes goes and sometimes doesn't. I do not know anything about using smtp server for sending emails, not aware internal configuration. I am just writing a php script in my hosted server. Just need to know anything wrong with my present script???? Quote Link to comment https://forums.phpfreaks.com/topic/184243-why-mails-are-not-going/#findComment-973146 Share on other sites More sharing options...
oni-kun Posted December 8, 2009 Share Posted December 8, 2009 There isn't. As the previous user posted, go into a command line you have (preferrably Windows for this command) and type: Telnet mail.yourdomain.com 25 Or whatever your mail server is. If it is unreachable or times out, than obviously that is the problem. Quote Link to comment https://forums.phpfreaks.com/topic/184243-why-mails-are-not-going/#findComment-973150 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.