Page 1 of 1

PHP Emailing - problems with links in email content

Posted: Thu Jul 27, 2006 11:09 am
by NateETB1
Everah | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I have been experiencing problems trying to send emails with php using the mail() command.

I have found that the mail command is sensitive to the content of the e-mail being sent, especially when there is html code in the e-mail, and even more often with <a> tags.

Example:

Code: Select all

<?php
$msg = "....";

$to = "email@server.com";
$subject = "Subject";
$mailheaders = "From : fromEmail \n";
$mailheaders .= "Reply-To : fromEmail@server.com\r\nContent-type: text/html; charset=us-ascii";


mail($to, $subject, $msg, $mailheaders);
?>
I have used this exact code, and found that success depends on the $msg variable.

1. It failed when $msg included the text
"<a href='http://www.ifesbuyersguide.org/classifieds.php'>View now</a>"
But it worked with
"<a href='http://www.ifesbuyersguide.org/classifi ... .php'>View now</a>"

I have found the same thing in other cases, where a link t a particular url causes the mail() command to fail


2. Once, I had a $msg that did not work until I removed a "<br/>" tag. Once I removed that tag, it worked fine. However, I've used <br/> tags with no problem in other emails.



Anybody have any idea what's going on here?


Thanks,
Nate


Everah | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Thu Jul 27, 2006 11:12 am
by RobertGonzalez
I'd be willing to bet it has something to do with the quotes used (single and double and not escaping one or the other.

Posted: Thu Jul 27, 2006 2:33 pm
by NateETB1
I don't think that's it. The problem comes and goes even if I don't touch the quotes

Posted: Thu Jul 27, 2006 3:13 pm
by RobertGonzalez
OK, so lets dig a little deeper. When you say it doesn't work, what is not working? Are you checking against an accepted mailing?

Code: Select all

<?php
if ( !mail($to, $subject, $msg, $mailheaders) )
{
    echo 'Mail not accepted!';
} else {
    echo 'Yay it went through!';
}
?>

Posted: Mon Jul 31, 2006 10:17 am
by NateETB1
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I ran the following two scripts.  The only difference is the content of the $msg variable.  In both cases the ''Yay it went through!' message was printed.  However, I did not receive the second message (which includes a hyperlink) in my mailbox.

-  I've checked my junk e-mail folder, and it's not there
-  I also tried a href=\"#\", and that didn't arrive in my mailbox either.

1.

Code: Select all

<?php
		
	$msg = "Thank you for submitting a listing to the Buyers Guide Classified section!  Your listing is now online";

	$to = "myemail@server.com";
	$subject = "Your listing is online at http://www.ifesbuyersguide.org";
	$mailheaders = "From : electionbuyersguide \n";
	$mailheaders .= "Reply-To : myemail@server.com\r\nContent-type: text/html; charset=us-ascii";

	if ( !mail($to, $subject, $msg, $mailheaders) ) 
	{ 
		echo 'Mail not accepted!'; 
	} else { 
		echo 'Yay it went through!'; 
	} 

?>
2.

Code: Select all

<?php							
     $msg = "Thank you for submitting a listing to the Buyers Guide Classified section!  Your listing is now online. <a href='http://www.google.com'>Link to google</a>";
							
								$to = "myemail@server.com";		
	$subject = "Your listing is online at http://www.ifesbuyersguide.org";
	$mailheaders = "From : electionbuyersguide \n";
	$mailheaders .= "Reply-To : myemail@server.com\r\nContent-type: text/html; charset=us-ascii";
	
         if ( !mail($to, $subject, $msg, $mailheaders) ) 
         { 
	echo "Mail not accepted!    $msg"; 
         } else { 
	echo "Yay it went through!   $msg"; 
         } 
?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Mon Jul 31, 2006 10:31 am
by RobertGonzalez
There is a possibility that there is a spam filter killing the mail. Can you receive web processed email from other servers with links in them?

Posted: Mon Jul 31, 2006 11:02 am
by NateETB1
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Not only can I receive web processed e-mail with links, sometimes it works when I send it to myself in just this way.

For example, the following code sends an e-mail, and I receive it in my box.

Code: Select all

<?php
									$msg = "A new listing has been posted on the buyer's guide classifieds page.<br/>
		<a href='http://www.ifesbuyersguide.com/classifieds_admin.php?listingID=$listingID&&action=showListing'>Go to the admin page</a> to review this listing and put it online. ";
	
                $to = "myemail@server.com";						$subject = "BUYERS GUIDE CLASSIFIEDS ORDER: ";				$mailheaders = "From : electionbuyersguide \n";				$mailheaders .= "Reply-To : myemail@server.com\r\nContent-type: text/html; charset=us-ascii";

	mail($to, $subject, $msg, $mailheaders);
									
										echo $msg;

?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Mon Jul 31, 2006 9:25 pm
by RobertGonzalez
Well, you got me. I really have no clue as to what could be happening.

Posted: Tue Aug 01, 2006 10:44 am
by NateETB1
And after I put all my faith in you

Posted: Wed Aug 02, 2006 8:58 pm
by RobertGonzalez
NateETB1 wrote:And after I put all my faith in you
Faith goes to God...or the chef if you are eating out.Image

Sorry to disapoint, but logically... well, there is no logic in this problem. Every other type of email message string gets through, some do that contain a link, some don't that contain a link, some do of the link is of a certain pattern. What logic is this? I am stumped. Image