I want to retrieve email from database and send message to all the email address.
I have written code for that but it is not working. I want someone to help me look at the code below and point out where am making mistakes and the correction.
The first page with code that retrieve all email from database and form to type the message
//Connect to database
//Form for the listing all email and textarea for message
echo '<form action="sendmail.php" method="GET" id="sendemail" >';
//Setting up the variable
$mailcount = 0;
$namecount = 0;
//retriving all email from database
$result = mysql_query("SELECT * FROM mailinglist WHERE Send='1'");
while($row = mysql_fetch_assoc($result))
//listing all the emails as checkbox together with their names and the email
echo '<input type="checkbox" name="mail_'.$mailcount++.'" value="'.$row['Email'].'" CHECKED>'.$row['FirstName'].' '.$row['LastName'].' ('.$row['Email'].')
<input type="hidden" name="name_'.$namecount++.'" value="'.$row['FirstName'].'">
<b> Message: </b><br/>
<textarea name="message" id="message"></textarea></p>
<input name="submit" type="submit" value="Send" />';
Below is the second page that process the form contents and also send the message.
My problem is that, when I tested it with wampserver, I will get these errors
Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\wamp\www\dashboard\sendmail.php on line 38
Notice: Undefined index: mail_3 in C:\wamp\www\dasboard\sendmail.php on line 26
Notice: Undefined index: mail_4 in C:\wamp\www\dasboard\sendmail.php on line 26
Notice: Undefined index: mail_5 in C:\wamp\www\dasboard\sendmail.php on line 26
Notice: Undefined index: mail_6 in C:\wamp\www\dasboard\sendmail.php on line 26
Notice: Undefined index: mail_7 in C:\wamp\www\dasboard\sendmail.php on line 26
When I used break; to stop the (for loop), I won't see the undefined index error.
But when I upload the code to live server and tested, I got only the Message failed with any error message.
Have you checked you php.ini file to see whether you SMTP address and port details are correct? I can't see line 38 in sendmail.php but that's the first place I would look according to your error message.
I can't see line 38 in sendmail.php but that's the first place I would look according to your error message.
You mis-read a part of the error wrong. The server displayed an error to check SMTP configuration details in php.ini, The server also suggested him to dynamically add SMTP settings to the script using ini_set() on the page.
@deyesborn, as StephNicolaou suggested, you should have a look into your SMTP settings. either change your php ini or add them on run by using ini_set();
I was able to figure out mistakes I made and it is working fine now. But the problem am having is that, when I send mail, two mails will be sent. One from my email I added to the send field and the other one from my cpanel username and host mailserver.