PDA

View Full Version : PHP script problem - please help!



peejay
October 27th, 2008, 08:47 AM
Hi all,

I have a PHP email script that's driving me mad. I bought a flash template and this came with it. There's no reason for it not to work. My hosting company sent another script that apparently works on my server but it's very different to the one I have and I have no idea how to transform it to work.

I've tried reloading the original file. I've checked spelling of my email addresses and replaced the yoursite.com with my domain name. I just can' figure it out and it's driving me mad. I need this up now, please help!

The script for the site reads like this:


<?php
$sendTo = "you@yoursite.com";
$subject = "Website info";
$message = $_GET['message'];
$email = $_GET['email'];
$name = $_GET['name'];
//send mail
$headers = "From: $email\r\n";
//$headers .= 'MIME-Version: 1.0' . "\r\n";
//$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$msg = "The following information has been submited via website:\n\nName:".$name."\n\nE-mail:".$email."\n\nMessage:".$message."";
mail($sendTo, $subject, $msg, $headers);
echo "status=formOk";
?>

The script that my hosting company sent reads like this:


<?php
$res = mail("attachments@hostingco.net", "Test PHP Mailer Script", "Hi, this is a test script", "From: root@yoursite.com", "-froot@yoursite.com");
if($res == 1){echo "Email sent sucsessfully."; } ?>

Can anyone see what might be going wrong? Any ideas how to transform the code to work with mine?

Thanks in advance!!!

Zoeman
October 28th, 2008, 07:25 PM
Sorry, but I don't understand what the problem is.
Are you getting an error? Does everything appear to work but you don't receive the email? Why do you think you need to transform your host's code?
Very confused...

Your code looks fine at a glance, so the problem might be with your form.

Mak Valley
October 28th, 2008, 08:33 PM
try using $_POST instead of $_GET and if your form method is GET then change that as well


also, i noticed that particular block of code doesn't have some sort of checking method to determine whether or not someone came from a form, you may want to concider something like this to control the potential massive flood of e-mails...

on your form:


$action = $_GET['action'];
$mailfrom = $_POST['mailfrom'];
$mailto = $_POST['mailto'];
$submitbtn = $_POST['submitbtn'];
$mailmsg = $_POST['mailmsg'];
$subject = $_POST['subject'];

function mail_form(){
echo "<form action=\"?action=sendmail\" method=\"post\"><br />\n";
echo "Mail TO: <input type=\"text\" name=\"mailto\" /><br />\n";
echo "Mail FROM: <input type=\"text\" name=\"mailfrom\" /><br />\n";
echo "Subject: <input type=\"text\" name=\"subject\" /><br />\n";
echo "Message: <br />\n";
echo "<textarea name=\"mailmsg\" rows=\"5\" cols=\"12\"></textarea><br />\n";
echo "<input type=\"submit\" name=\"submitbtn\" value=\"Send\" />\n";
}
if ($action == "sendmail"){
if (isset($submitbtn)){
mail ($mailto, $subject, $mailmsg, "From: $mailfrom");
echo "Mail sent.";
} else {
echo "You didn't come from a form.";
}
} else {
mail_form();
}


this was pretty much typed off the top of my head but it should work

tfg
October 30th, 2008, 08:30 AM
looks like you need to add the -f switch to the mail function. i know of a few hosts that require this to combat spam.

$yourEmailAddress = "peejay@peejay.net"; // this will probably need to be a valid email address hosted on your server
mail($sendTo, $subject, $msg, $headers, "-f" . $yourEmailAddress);