PHP Mail Function Not Working?

Status
Not open for further replies.

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.
 

bdistler

Well-Known Member
Prime Account
Messages
3,534
Reaction score
196
Points
63
As a start.....
add this line as line #2 in your scrip (until you get it to work) --> error_reporting(E_ALL); <--
you should test --> $_POST["email"] - to be sure it is what you think it is
where did you setup the array --> $row ? - and is it what you think it is

use plan text for [ $message ] - not HTML
replace --> "Content-type: text/html; charset=iso-8859-1\r\n" <-- with --> 'Content-type: text/plain; charset=\"iso-8859-1\"' . "\r\n" <-- note the quotes

the "from:" Email address must be a valid Email address on your account's domain - that is one you added to your account

you should test the mail() function with something like...
Code:
if(mail($to, $subject, $message, $headers))
  {
    print "PHP mail() returned TRUE<br>\n";
  }
  else
    {
      print "ERROR sending Email - PHP mail() returned FALSE<br>\n";
    }

PHP function [ mail() ] returns TRUE if the mail was successfully accepted for delivery, FALSE otherwise
It is important to note that just because the mail was accepted for delivery
it does NOT mean the mail will actually reach the intended destination

while not 100% - if you add the "From:" Email address to the "To:" Email address line after a comma
then most of the time when it did not reach the intended destination - you can 'see' a copy of your Email with your account's Webmail (in cPanel or your browser)
 

iharmi53

New Member
Messages
13
Reaction score
0
Points
1
thanks for your reply, i have tried what you said and it still doesn't work, so now i just took the simple script from php mail reference itself, and it still doesn't work and it does return true, here is the code:

PHP:
$message = "Line 1\r\nLine 2\r\nLine 3";
        $message = wordwrap($message, 70, "\r\n");
        $headers = 'From: noreply@iharmi.elementfx.com'."\r\n";
        if(mail('******@hotmail.com', 'My Subject', $message, $headers)){
            echo("true");
        }else{
            echo("false");
        }

Can you tell me why it doesn't send? Now I have taken the most simple script but it still doesn't work.
 
Last edited by a moderator:

bdistler

Well-Known Member
Prime Account
Messages
3,534
Reaction score
196
Points
63
I assume you have set up this Email address in your free-hosting account on server [ Level ] --> [ noreply@iharmi.elementfx.com ]

change this line --> [ if(mail('iharmi@hotmail.com', 'My Subject', $message, $headers)){ ]
to --> [ if(mail("iharmi@hotmail.com, noreply@iharmi.elementfx.com", 'My Subject', $message, $headers)){ ]
after a run you should see a copy in your account cPanel (not x10hosting Basic!) Webmail

for weeks now - in my free-hosting account which is on server [ Level ] I can send Emails with PHP mail() function - to a Email address in that account but can can not send to any Email address outside of that account or to my Email address in my x10hosting Premium account - which is not on the same server
no errors - they get put into the bit bucket
 

Skizzerz

Contributors
Staff member
Contributors
Messages
2,929
Reaction score
118
Points
63
Looking at our email server, I see 15 messages outgoing from your account, and all of them were successfully sent -- check your spam/bulk folder of your hotmail account to see if they wound up there.
 
Status
Not open for further replies.
Top