PHP Mail Function Not Working?

iharmi53

New Member
Messages
13
Reaction score
0
Points
1
Hello guys,

I have created this PHP script:

PHP:
$to = $_POST["email"];
$subject = "FW-Bestilling.DK - Dit brugernavn";

$message = "<html>
<head>
    <title>FW-Bestilling.DK - Dit brugernavn</title>
</head>
<body>

<p><b>Dit brugernavn er:</b> ".$row["user_username"]."</p>

</body>
</html>";
$message = wordwrap($message, 70, "\r\n");

$headers  = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: test <noreply@test.dk>\r\n";

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

But I don't receive any e-mails to my e-mail (and I do have writen my proper email address into $to), have I done something wrong? Or is the mail function disabled for free x10hosting users? Please help me out.
 

rooxx102

New Member
Messages
18
Reaction score
0
Points
1
Change;
PHP:
$message = wordwrap($message, 70, "\r\n");
to;
PHP:
$message2 = wordwrap($message, 70, "\r\n");

and add '$message2' to your mail(); query.
 

caftpx10

Well-Known Member
Messages
1,534
Reaction score
114
Points
63
Do what roxx102 said, you were basically overwriting a variable.
You need both so using different names would be the best option.
 

essellar

Community Advocate
Community Support
Messages
3,295
Reaction score
227
Points
63
The $x = do_something_to($x); syntax is perfectly fine and will only very rarely cause problems in very specific circumstances, which should be regarded as environmental bugs. (Under the hood, a new string is created with a temporary "name", and its address (pointer, if you will) is assigned to the named variable, abandoning both the old string and the temporary variable. Strings are immutable in most languages; "changing" them means creating a new one and destroying the old one. At no time does $message contain both values, nor is there any point at which there would be any ambiguity.)

The problem here is that HTML mail won't make it out of the system (phishing and other tricksies are too easy to do with blind links, webbugs and so forth, and getting one of the Free Hosting servers placed on a spam blacklist knocks out everybody's mail and takes a lot of effort to fix). Your email needs to have a plain text part at least, and may need to be just plain text (depending on how the outgoing spam filter is set up at the time).

If you need fancy formatting for newsletters or marketing pieces, take a look at outboard services like MailChimp/Mandrill (which often have reasonable free level services).
 
Top