English 中文(简体)
Why is the From line not working on my mail function?
原标题:

I am using a mail function to send html to an email address, but the From name and email address aren t showing up. This is my code:

$name = $_POST[ name ];
$mailTo =  name@email.com ;
$subject =  Message from   . $_POST[ name ];
$message = 
             <html>
            <head>
            <title>HTML email</title>
            </head>
            <body>
            <p><b>Name:</b>   . $_POST[ name ] .  </p>
            <p><b>Email:</b>   . $_POST[ email ] .  </p>
            <p><b>Message:</b>   . $_POST[ mainmessage ] .  </p>
            </body>
            </html> ;

$headers  =  MIME-Version: 1.0  . "
";
$headers .=  Content-type: text/html; charset=iso-8859-1  . "
";
$headers .=  From: Postmaster <some@body.com> ;

mail($mailTo, $subject, $message, $headers);

I would expect the email to show up as being from Postmaster at the email address some@body.com, but it is showing up as coming from ideapale@box486.bluehost.com, which is my hosting provider.

What did I not set up correctly?

最佳回答

Chris, try adding the after the <some@body.com>. I ve found that php can be very picky when talking to mail servers.

Edit: just to help a little more, I have this (almost exactly what you have) in one of my working scripts:

$headers  =  MIME-Version: 1.0  . "
";
$headers .=  Content-type: text/html; charset=iso-8859-1  . "
";
$headers .=  To:  .$to . "
";
$headers .=  From:   .$from. "
";

...where $from = $fromname. < .$fromemail. > ; and $to is just an email address.

问题回答

暂无回答




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签