Whenever I send a mail via PHP (content generated by jQuery, AJAX POST to PHP) the base of the URL gets missing when arriving at the destination.
So for instance, I send a mail with the following body:
Click <a href="http://www.example.com/?u=parameter&i=otherparameter">HERE</a> to go to the login page, etc, etc..
Use this link or copy it to your browser's address bar if the above doesn't work:
<a href="http://www.example.com/?u=parameter&i=otherparameter">http://www.example.com/?u=parameter&i=otherparameter</a>
Which looks like this:
Click HERE to go to the login page, etc, etc..
Use this link or copy it to your browser’s address bar if the above doesn’t work:
http://www.example.com/?u=parameter&i=otherparameter
But, the receiver gets the same text, only without the links’ base URL..
The link of Click HERE has the URL of only /?u=parameter&i=otherparameter, same goes for the other link, but the text of that link is fine. So it goes to the page where the mail is opened and appends the parameters there. It looks like this:
Click HERE to go to the login page, etc, etc..
Use this link or copy it to your browser’s address bar if the above doesn’t work:
http://www.example.com/?u=parameter&i=otherparameter
As you can see, the link will be directed to stackoverflow.com, instead of example.com. What is happening that either jQuery, AJAX or PHP strips my HTML, or is it a clientside problem?
(Tested in FF15/Chrome20/IE8, jQuery v1.7.2, PHP v5.3.5)
EDIT
This is how I send the mail with PHP:
$to = $_POST['t'];
$subject = $_POST['s'];
$message = $_POST['m'];
$headers = "MIME-Version: 1.0" . "\r\n" .
"Content-type: text/html; charset=iso-8859-1" . "\r\n" .
"From: <noreply@example.com>" . "\r\n" .
"X-Mailer: PHP/" . phpversion();
mail($to, $subject, $message, $headers);
a quick solution is to use the define the base url with the _SERVER global array read documentation at php manual for more.but the mail function should not fail…
Also where does AJAX come in in the posting of mails… that’s php mail() function.Are you retrieving values from users or are the values dynamically retrieved using the php or a database….