busnut Posted January 21, 2009 Share Posted January 21, 2009 G'day guys I've got a script that has a mail function, and once the unit hits 'Send Mail', it then displays all the people that it has sent the mail to, but not everyone has a email address recorded in their profile, and this is what it currently shows (name & email address, although everyones name is in the database, if there is no email address, it shows a blank as listed below): Success sending to: Admin - [email protected] Success sending to: Admin2 - [email protected] Error: Failed sending to: Success sending to: Admin4 - [email protected] to show this: Success sending to: Admin - [email protected] Success sending to: Admin2 - [email protected] Error: Failed sending to: Admin3 - no email adress recorded Success sending to: Admin4 - [email protected] here is the script if ($page=="send") { $result = mysql_query("SELECT * FROM membership"); while ($row = mysql_fetch_array($result)){ $name = $row['name']; $username = $row['username']; $email = $row['email']; $message = "Hello $name,\n\n"; $to = $email; if(mail($to, $subject, $message, "From: Club Name")){ echo "Success sending to: $name - $to<br>"; }else{ echo "<font color=\"#FF0000\">Error:</font> Failed sending to: $to<br>"; }//end else }//end while } Cheers Link to comment https://forums.phpfreaks.com/topic/141710-solved-php-mailout/ Share on other sites More sharing options...
Zane Posted January 21, 2009 Share Posted January 21, 2009 well first....why do you have three variables for the email address? $row['email'] is the email address. $email is the email address. $to is also the email address. personally I'd just stick with $row['email'], but anyway This should do ya if(mail($to, $subject, $message, "From: Club Name")){ echo "Success sending to: $name - $to "; }else{ echo "Error: Failed sending to :$name - No email address recorded. "; Link to comment https://forums.phpfreaks.com/topic/141710-solved-php-mailout/#findComment-741869 Share on other sites More sharing options...
busnut Posted January 21, 2009 Author Share Posted January 21, 2009 I must be having a blonde day, why I never thought to change $to to $name i've got no idea But thanks for that, most appreciated! But as for the other bit you mentioned, now that you've pointed it out, it does make sense that they all mean the same thing, will look into that later. But I do have one other issue that i've just noticed, when I type the message out and the message gets sent, it adds other characters into the email sent, so I type this: i wish i knew more about 'programming' and it comes out like this: i wish i knew more about \'programming\' but i'm not sure how to fix this issue here is my form code if its any help? echo "<form method=\"POST\" action=\"?page=send\"> <table align=\"center\" border=\"0\" width=\"500\" cellpadding=\"2\"> <tr> <td>Subject:</td> <td><input type=\"text\" name=\"subject\" size=\"27\" value=\"\"></td> </tr> <tr> <td valign=\"top\">Message:</td> <td>Hello (username inserted),<br> <textarea rows=\"20\" name=\"msg\" cols=\"80\"></textarea> <br> ----------------------------------<br> </td> </tr> <tr> <td> </td> <td><input type=\"hidden\" name=\"action\" value=\"send\"> <input type=\"submit\" value=\"Send Mail\" style=\"width: 150px;\"></td> </tr> </table>"; } Link to comment https://forums.phpfreaks.com/topic/141710-solved-php-mailout/#findComment-741882 Share on other sites More sharing options...
Zane Posted January 21, 2009 Share Posted January 21, 2009 mail($to, $subject, stripslashes($message), "From: Club Name") Link to comment https://forums.phpfreaks.com/topic/141710-solved-php-mailout/#findComment-741885 Share on other sites More sharing options...
busnut Posted January 21, 2009 Author Share Posted January 21, 2009 mail($to, $subject, stripslashes($message), "From: Club Name") Geez, that was quick and believe it or not, brilliant. I can not believe it was something as simple as that. I saw a script a long time ago that had something like if it has all these types of markings, to not put the slash around it, and it seemed pretty long winded, so thanks once again. A very simple and quick fix, most appreciated Link to comment https://forums.phpfreaks.com/topic/141710-solved-php-mailout/#findComment-741892 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.