Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Mail

mail() adding spaces to url in body of email

the mail() function

Moderators: macek, egami, gesf

mail() adding spaces to url in body of email

Postby ericwshoemaker » Mon Aug 15, 2011 6:05 pm

Hello. Here is my email code:

Code: Select all
function sendWelcome($user, $email, $pass){
      $headers = "From: ".EMAIL_FROM_NAME." <".EMAIL_FROM_ADDR.">\r\n";
      $headers .= "MIME-Version: 1.0\r\n";
      $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
      $subject = "Welcome";
      $body = "<html><body>"
             ."Hey ".$user.",<br /><br />"
             ."Congratulations! You are now officially part of the community. "
             ."Username: ".$user."<br /><br />"
             ."Password: ".$pass."<br /><br />"
        ."<a href=\"".DOMAIN_URL."?action=login\">Click "
        ."here to login and begin posting.</a> "
        ."Enjoy!<br /><br />"
        ."Thank you for choosing us!<br /><br />"
             ."</body></html>";

      return mail($email,$subject,$body,$headers);


There is some more unimportant text that comes along with it, but this is the gist of how it's structured.

The problem, when I get the emails in my inbox, the URL i'm getting the following as the href for my URL:
http://www.goog%20%20le.com/?action=login

Any idea why the spaces are getting put in there? I have DOMAIN_URL defined as "http://www.google.com"

It's strange that these space characters are coming in here, as I use this method with other emails and there is not an issue.
ericwshoemaker
New php-forum User
New php-forum User
 
Posts: 1
Joined: Mon Aug 15, 2011 5:56 pm

Re: mail() adding spaces to url in body of email

Postby bigjoe11a » Tue Sep 27, 2011 3:34 pm

Try this below and I will all so need to see what your DOMAIN_URL looks like too

Code: Select all
 function sendWelcome($user, $email, $pass){
 
 $headers = "From: ".EMAIL_FROM_NAME." <".EMAIL_FROM_ADDR.">";
 $headers .= "MIME-Version: 1.0";
 $headers .= "Content-Type: text/html; charset=ISO-8859-1";
 $subject = "Welcome";
$body = <<<HTML
<html><body>
Hey ".$user.",<br /><br />
Congratulations! You are now officially part of the community.<br />
Username: ".$user."<br /><br />"
Password: ".$pass."<br /><br />
<a href=".DOMAIN_URL."?action=login">Click</a><br />
here to login and begin posting.</a>
Enjoy!<br /><br />
Thank you for choosing us!<br /><br />
</body></html>
HTML;
return mail($email,$subject,$body,$headers);

}
User avatar
bigjoe11a
New php-forum User
New php-forum User
 
Posts: 128
Joined: Wed Aug 31, 2011 3:55 am
Location: USA


Return to PHP coding => Mail

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.