...

View Full Version : php email



xmldevnewcastle
11-01-2007, 06:13 PM
trying to write an email script, been banging my head off the wall for hours, can anyone see anything wrong with this?




<?

$failure = 0;

error_reporting(0);

$errorlist = " ";

if(isset($_POST["Name"]) && $_POST["Name"] !="")
{
$name = $_POST["Name"];
}

else
{
$name = "";
$failure = 1;
$errorlist .= "A name is required.<br />";
}

if(isset($_POST["Subject"]) && $_POST["Subject"] !="")
{
$subject = $_POST["Subject"];
}

else
{
$subject = "";
$failure = 1;
$errorlist .= "Please provide a subject for this query so we can send it to the relevant department. <br />";
}

if(isset($_POST["Where"]) && $_POST["Where"] !="")
{
$where = $_POST["Where"];
}

else
{
$where = "";
$failure = 1;
$errorlist .= "Please state where you found us (yell.com, google etc).<br />";
}

if(isset($_POST["Email"]) & $_POST["Email"] !="")
{
$email = $_POST["Email"];
list($username,$domain) = split("@",$email);
}

else
{
$email = "";
}

if($domain == "")
{
$failure = 1;
$errorlist .= "Please provide a valid email address.<br />";
}

if(isset($_POST["Content"]) && $_POST["Content"] !="")
{
$content = $_POST["Content"];
}

else
{
$content = "";
$failure = 1;
$errorlist .= "Please provide some comments.<br />";
}

if($failure !=0)
{

if(isset($_POST["Posted"]))
{
echo("<p style='color:red;'>");
echo($errorlist);
echo("</p>");
}
?>

<form action="" method="post" class="contact">

<label for="name">Name:</label>

<input type="text" name="Name" id="name" value="<?=$name?>" />

<label for="email">E-mail:</label>

<input type="text" name="Email" id="email" value="<?=$email?>" />

<label for="subject">Subject:</label>

<input type="text" name="Subject" id="subject" value="<?=$subject?>" />

<label for="where">Where did you hear about us:</label>

<input type="text" name="Where" id="where" value="<?=$where?>" />

<label for="Content" style="margin-left:-120px;">Comments:</label>

<input type="hidden" name="Posted" ID="posted" value="1">

<textarea name="Content" ID="Content" style="width:450px; height:150px; margin-top:15px; _margin-top:-15px;">
<?=$content?>
</textarea>

<input type="submit" value="Send" style="width:70px; margin-top:15px; margin-left:252px;" />

</form>
<?
}

else
{
echo("<P>Thank you $name for your message. We will get back to you ASAP.</P>");

$msg = "<table border=0 style='border:1px solid #000000;'>";
$msg .= "<tr><td><img src='http://astra.streamlinenettrial.co.uk/images/header.jpg' style='width:750px; height:100px;' /></td></tr>";
$msg .= "<tr><td>";

$msg .= "<p><strong>From:</strong> $name</p>";
$msg .= "<p><strong>Subject:</strong> $subject</p>;";
$msg .= "<p><strong>Found us at:</strong> $where</p>;";
$msg .= "<p><strong>Comments:</strong><br /><br /> $content</p>;";

$msg .= "</td></tr>";
$msg .= "</table>";

$recipient = "ttpparker@talk21.com";


// To send HTML mail, the Content-type header must be set
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=ISO-8859-1\r\n";

// Additional headers
$headers .= "From: TIM ParMEN <ttpparker@talk21.com>\r\n";
$headers .= "Reply-To: $email";

echo($subject);
echo($recipient);
echo($headers);


mail($recipient, $subject, $msg, $headers);
}
?>

CFMaBiSmAd
11-01-2007, 06:22 PM
And what it is doing or not doing so that we know what we should be looking at to help you with? There could literally be a hundred different things wrong. You need to narrow it down a bit.

xmldevnewcastle
11-01-2007, 06:34 PM
just not sending the email, doesnt return an error (even if i turn errors on).

Fumigator
11-01-2007, 07:07 PM
Wow that was helpful.

Does the mail() function return true or false? I see you've added echo statements to see what's in your mail variables. And?

Add print_r($_POST) to the top of the script and see what that tells you.

xmldevnewcastle
11-01-2007, 07:20 PM
mail doesnt return anything, the echo of the variables print out what i expect them to.

print_r($_POST) returns all the form fields and it all seems in order.

Im not sure what it is you need to know, anything in paticular?

Fumigator
11-01-2007, 07:44 PM
From the manual:

Returns TRUE if the mail was successfully accepted for delivery, FALSE otherwise.

xmldevnewcastle
11-02-2007, 11:05 AM
im pretty new to php, how would i get to output whether its true or false?

aedrin
11-02-2007, 05:11 PM
if (mail($recipient, $subject, $msg, $headers)) {
echo 'Mailed succesfully!";
} else {
echo "A problem occured while attempting to mail.";
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum