Jump to content


mail() function problem


6 replies to this topic

#1 N-GAGE

    Young Padawan

  • Members
  • Pip
  • 29 posts
  • Gender:Male
  • Location:Madrid / Spain
  • Interests:Web design/development

Posted 24 July 2008 - 04:18 PM

Hello everyone,

<?
		$email = "myemail@gmail.com";
		$subiect = "Trying";
		$mesaj = "Hello";
		$headers = 'From: My Name' . "\r\n" .
				   'Reply-To: My Name' . "\r\n";
		
        mail($email,$subiect, stripslashes($mesaj), $headers);
?>

If I run this code, in the email box I'll get a new email in which the name is without space.
I'll get a new message with from "MyName".


Does anybody have any idea how to fix this ?
I searched a lot in the php manual and in google but nothing helped me.


Thanks

#2 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 24 July 2008 - 06:57 PM

Awkward. Random idea: try url encoding
'From: My%20Name'
Worst thing that can happen is nothing.

#3 N-GAGE

    Young Padawan

  • Members
  • Pip
  • 29 posts
  • Gender:Male
  • Location:Madrid / Spain
  • Interests:Web design/development

Posted 25 July 2008 - 09:51 AM

View Postrc69, on Jul 25 2008, 01:57 AM, said:

Awkward. Random idea: try url encoding
'From: My%20Name'
Worst thing that can happen is nothing.

I tried this and the result: from My%20Name@... .. The %20 doesn't change in anything.

Besides, I tried urlencode($name) and I get My+Name;
I tried too My&nbsp;Name and the result is: My&nbsp


Anyone else ?

#4 Tirus

    P2L Jedi

  • Members
  • PipPipPip
  • 764 posts
  • Gender:Male
  • Location:Montreal, Canada
  • Interests:Web Design, Programming, Music, Martial Arts

Posted 25 July 2008 - 10:30 PM

try enclosing the entire headers variable in another set of double quotes:

<?
$email = "myemail@gmail.com";
$subiect = "Trying";
$mesaj = "Hello";
$headers = "'From: My Name' . \r\n .
'Reply-To: My Name' . \r\n";

mail($email,$subiect, stripslashes($mesaj), $headers);
?>

I haven't tested it but see what you get. (I also removed the double quote before/after the \r\n.)

just a suggestion, try it out.

Edited by Tirus, 26 July 2008 - 09:13 AM.


#5 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 26 July 2008 - 01:02 AM

Tirus, please refer to the following page on php.net: Strings

I don't want to sound rude, and i don't want to go into why what you did with the $headers variable is wrong, but trust me when i say that what you did is really not right.

The only remaining issue i can come up with for why the space is being removed is because of either your e-mail client, or something with your SMTP server that removes spaces (which would be out of your control and you should talk to your hosts customer support for help with that).

Edited by rc69, 26 July 2008 - 01:03 AM.


#6 Tirus

    P2L Jedi

  • Members
  • PipPipPip
  • 764 posts
  • Gender:Male
  • Location:Montreal, Canada
  • Interests:Web Design, Programming, Music, Martial Arts

Posted 26 July 2008 - 09:12 AM

rc69, you're very right, just realized what I was doing wrong, thanks for pointing it out.


N-GAGE, please ignore the above suggestion :P

#7 N-GAGE

    Young Padawan

  • Members
  • Pip
  • 29 posts
  • Gender:Male
  • Location:Madrid / Spain
  • Interests:Web design/development

Posted 27 July 2008 - 04:36 PM

View PostTirus, on Jul 26 2008, 04:12 PM, said:

rc69, you're very right, just realized what I was doing wrong, thanks for pointing it out.


N-GAGE, please ignore the above suggestion :)

Ok people... finally I resolved it myself

I was simple :)

<?
		$email = "youremail@gmail.com";
		$subiect = "Trying";
		$mesaj = "Hello";
		$headers = 'From: "Your Name" <jojo@gmail.com>' . "\r\n" .
				   'Reply-To: "Your name"' . "\r\n";
		
        mail($email,$subiect, stripslashes($mesaj), $headers);
?>

Just putting the name in "" will do.

Keep this in mind.

Thanks anyway 2 everyone





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users