Jump to content

Recommended Posts

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 - webmaster@domain.com

Success sending to: Admin2 - admin2@domain.com

Error: Failed sending to:

Success sending to: Admin4 - admin4@domain.com

 

to show this:

Success sending to: Admin - webmaster@domain.com

Success sending to: Admin2 - admin2@domain.com

Error: Failed sending to: Admin3 - no email adress recorded

Success sending to: Admin4 - admin4@domain.com

 

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

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

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

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.

×
×
  • 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.