Jump to content

Mail Function not Working


Rowno

Recommended Posts

Can anyone tell me why this script isn't sending any emails?

<?php
$message = "
<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
<html xmlns=\"http://www.w3.org/1999/xhtml\">
<head>
<title>$subject</title>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />
<style>
body
{
font-family:Arial;
} 
</style>
</head>
<body>
This email was sent by $name from the WEB SPIRITED Contact Us mail form and they sent this message:<br />
$message
<br />
Their reply email address is: $email
</body>
</html>
";
$message = wordwrap($message, "70");
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type:text/html;charset=iso-8859-1' . "\r\n";
$headers .= 'From: WEB SPIRITED <from email here>' . "\r\n";
$headers .= 'Reply-To: '.$email . "\r\n";

if ($subject == "I would like a website made")
{$toemail = "email 1";}
else
{$toemail = "email 2";}

if (mail($toemail, $subject, $message, $headers))
{
$success = "Your email has been sent.";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/103335-mail-function-not-working/
Share on other sites

Hello, had a similar problem with HTML based email not to long ago myself..

 

After pleanty of agravasion and trial and error and help from here even.. I got all to work..

 

 

<?php
$to = $_POST['ref_trmail'];
$subject = '[Poetry Asylum] - ' . $ptitle;
$message = '
Your message here, including HTML markup..
';
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'Content-type: text/html; charset=us-ascii' . "\r\n";
$headers .= 'From: Poem Share <[email protected]>' . "\r\n";
$headers .= 'To: ' . $_POST['ref_trname'] . ' <' . $_POST['ref_trmail'] . '>' . "\r\n";
$headers .= 'Reply-To: ' . $_POST['ref_yrname'] . ' <' . $_POST['ref_yrmail'] . '>' . "\r\n";
$headers .= '1\r\nX-MSMail-Priority: High' . "\r\n";
$headers .= 'X-Mailer: Poetry Asylum mailer v1.0' . "\r\n";
mail($to, $subject, $message, $headers);

 

now heres where I got thrown off and looks similar to you one...

your escapes of the double quotes in the message, take them out just leave the plain double quote like you would in any other html doc...

 

two pay attention to my version vs yours.. notice the single quotes vs the double quotes, and where they are placed..

 

thrid you may wanna change it up a smidge as I have left headers and what not that pertain to mine as im just copy an pasting it out of one of my files for examples sake..

 

fourth when you have changed what you need and added your stuff in the part that says your message here you should have a fully functional HTML sending php mailer..

 

Enjoy

There is nothing wrong with the message, as I echoed out the variables to see if they were being set and the html message looked perfect and the my server does send mail because I have another mail script on my site that works perfectly but for some reason this script doesn't.

OK shot in the dark as I suspect this is actually part of a bigger script but I don't see $subject being set anywhere...

 

In fact none of them are 'Set' anywhere in the script so perhaps you could post all the preceeding code also...

Ok, here's my other mail script that works perfectly:

<?php
            $subject = "WEB SPIRITED Email Verification and Account Activation";

            $message = "
<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
<html xmlns=\"http://www.w3.org/1999/xhtml\">
<head>
<title>WEB SPIRITED Email Verification and Account Activation</title>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />
<style>
body
{
font-family:Arial;
} 
</style>
</head>
<body>
This email was send by WEB SPIRITED to verify that the email address you entered is correct and to activate your account.<br />
Please click on the link below to verify this email address and to activate your account.
<p>
<br />
<a href=\"link" title=\"Verify email and activate account\">link</a>
<p>
<br />
If this link isn't working, copy and paste the address into the address field of your internet browser.
</body>
</html>
";
            $message = wordwrap($message, "70");

            $headers = 'MIME-Version: 1.0' . "\r\n";
            $headers .= 'Content-type:text/html;charset=iso-8859-1' . "\r\n";
            $headers .= 'From: WEB SPIRITED <from email here>' . "\r\n";

            mail($email, $subject, $message, $headers);
?>

Can anyone see any reason why the script above shouldn't work compared to this one? Because they're both run on the same server and same site.

try this fill in the correct info

<?php


$message = "
<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
<html xmlns=\"http://www.w3.org/1999/xhtml\">
<head>
<title>$subject</title>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />
<style>
body
{
font-family:Arial;
} 
</style>
</head>
<body>
This email was sent by $name from the WEB SPIRITED Contact Us mail form and they sent this message:<br />
$message
<br />
Their reply email address is: $email
</body>
</html>
";
$mess = wordwrap($message, "70");


$subject == "I would like a website made";

$name=" name off user";

$to="to the user email address";

$email=" from address email"

$to = $to;
$subject = $subject;
$message = $mess;
$headers = "From: $email\r\n" .
        'X-Mailer: PHP/' . phpversion() . "\r\n" .
        "MIME-Version: 1.0\r\n" .
        "Content-Type: text/html; charset=utf-8\r\n" .
        "Content-Transfer-Encoding: 8bit\r\n\r\n";



if ($subject == "I would like a website made"){

$toemail = "email 1";

}else{

$toemail = "email 2";
}

if (mail($to, $subject, $message, $headers)){

$success = "Your email has been sent.";
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.