Emailer code not working!
11-18-2007, 09:36 AM
|
Emailer code not working!
|
Posts: 26
Name: Darren Driver
|
Hi all,
I'm having problems with an emailer code I'm working on. Basically, what I want my code to do is to take the variables from a form on a previous page and send a mail to a different email address depending on what person has been selected.
For this, I have put 'contact' as the person who the person wishes to contact, 'subject' as the subject of the email, 'message' as what's to be said in the email, 'name' as the person sending the email and 'email' for the sender's email address.
The code I have has been programmed to come up with an error message if subject, message, name and email have been left blank, and to also come up with an error if 'contact' somehow comes up as something different to what's been given (this is given as a drop down menu on the previous page).
I've debugged this and all of this works flawlessly, however, as soon as I add the mail() code in, it doesn't work. What am I doing wrong here? I've given the code I have below:
PHP Code:
<?php if (( $_POST['subject'] == "" ) || ( $_POST['message'] == "" ) || ( $_POST['name'] == "" ) || ( $_POST['email'] == "" )) { echo "<b>Some of the fields required have been left blank.</b>"; echo "<br/>"; echo "In order to process your request, all fields must be filled in."; } else { if ( $_POST['contact'] == "Lawrence Whittaker (Comittee Chairman)" ) { if (mail("example@site.com, "Continuum Convention: $_POST['subject']", "$_POST['message']", "From: $_POST['name']\Reply-to: $_POST['email']")) { echo "Success!"; } else { echo "Failure."; } } elseif ( $_POST['contact'] == "Colin Driver (Events, Programme & Miniatures)" ) { if ( $_POST['contact'] == "Lawrence Whittaker (Comittee Chairman)" ) { if (mail("example@site.com, "Continuum Convention: $_POST['subject']", "$_POST['message']", "From: $_POST['name']\Reply-to: $_POST['email']")) { echo "Success!"; } else { echo "Failure."; } } elseif ( $_POST['contact'] == "Simon Bray (Freeforms)" ) { if ( $_POST['contact'] == "Lawrence Whittaker (Comittee Chairman)" ) { if (mail("example@site.com, "Continuum Convention: $_POST['subject']", "$_POST['message']", "From: $_POST['name']\Reply-to: $_POST['email']")) { echo "Success!"; } else { echo "Failure."; } } elseif ( $_POST['contact'] == "Graham Spearing (RPG, Board & Card Games)" ) { if ( $_POST['contact'] == "Lawrence Whittaker (Comittee Chairman)" ) { if (mail("example@site.com, "Continuum Convention: $_POST['subject']", "$_POST['message']", "From: $_POST['name']\Reply-to: $_POST['email']")) { echo "Success!"; } else { echo "Failure."; } } elseif ( $_POST['contact'] == "Darran Sims (Customer Service)" ) { if ( $_POST['contact'] == "Lawrence Whittaker (Comittee Chairman)" ) { if (mail("example@site.com, "Continuum Convention: $_POST['subject']", "$_POST['message']", "From: $_POST['name']\Reply-to: $_POST['email']")) { echo "Success!"; } else { echo "Failure."; } } elseif ( $_POST['contact'] == "Mike Mason (Auction & Registration)" ) { if ( $_POST['contact'] == "Lawrence Whittaker (Comittee Chairman)" ) { if (mail("example@site.com, "Continuum Convention: $_POST['subject']", "$_POST['message']", "From: $_POST['name']\Reply-to: $_POST['email']")) { echo "Success!"; } else { echo "Failure."; } } else { echo "<b>Comittee member not recognised.</b>"; echo "<br/>"; echo "Please go back and try again."; } } ?>
|
|
|
|
11-18-2007, 09:47 AM
|
Re: Emailer code not working!
|
Posts: 462
Name: Jerod Lycett
Location: /home/arenlor
|
Try this:
PHP Code:
mail("example@example.com", "Subject: Continuum Convention: $_POST['subject']", $_POST['message'],"From: $_POST['name']\r\nReply-to: $_POST['email']")
Also, proofread your code. you have mail("example@site.com, "blahblahblah when it should be .com",
Last edited by Arenlor; 11-18-2007 at 09:50 AM..
Reason: Added advice on proofreading
|
|
|
|
11-18-2007, 11:44 AM
|
Re: Emailer code not working!
|
Posts: 340
Name: Jon
Location: New York
|
try this, you need to proof your code, and if it throughs some errors look at it, alot of your intial script was in read meaning it had an open quote somewere  so try this
PHP Code:
<?php
if (( $_POST['subject'] == "" )
|| ( $_POST['message'] == "" )
|| ( $_POST['name'] == "" )
|| ( $_POST['email'] == "" ))
{
echo "<b>Some of the fields required have been left blank.</b>";
echo "<br/>";
echo "In order to process your request, all fields must be filled in.";
}
else
{
if ( $_POST['contact'] == "Lawrence Whittaker (Comittee Chairman)" )
{
if (mail("example@site.com", "Continuum Convention: $_POST['subject']", "$_POST['message']", "From: $_POST['name']Reply-to: $_POST['email']"))
{
echo "Success!";
}
else
{
echo "Failure.";
}
}
elseif ( $_POST['contact'] == "Colin Driver (Events, Programme & Miniatures)" )
{
if ( $_POST['contact'] == "Lawrence Whittaker (Comittee Chairman)" )
{
if (mail("example@site.com", "Continuum Convention: $_POST['subject']", "$_POST['message']", "From: $_POST['name']\Reply-to: $_POST['email']"))
{
echo "Success!";
}
else
{
echo "Failure.";
}
}
elseif ( $_POST['contact'] == "Simon Bray (Freeforms)" )
{
if ( $_POST['contact'] == "Lawrence Whittaker (Comittee Chairman)" )
{
if (mail("example@site.com", "Continuum Convention: $_POST['subject']", "$_POST['message']", "From: $_POST['name']Reply-to: $_POST['email']"))
{
echo "Success!";
}
else
{
echo "Failure.";
}
}
elseif ( $_POST['contact'] == "Graham Spearing (RPG, Board & Card Games)" )
{
if ( $_POST['contact'] == "Lawrence Whittaker (Comittee Chairman)" )
{
if (mail("example@site.com", "Continuum Convention: $_POST['subject']", "$_POST['message']", "From: $_POST['name']\Reply-to: $_POST['email']"))
{
echo "Success!";
}
else
{
echo "Failure.";
}
}
elseif ( $_POST['contact'] == "Darran Sims (Customer Service)" )
{
if ( $_POST['contact'] == "Lawrence Whittaker (Comittee Chairman)" )
{
if (mail("example@site.com", "Continuum Convention: $_POST['subject']", "$_POST['message']", "From: $_POST['name']Reply-to: $_POST['email']"))
{
echo "Success!";
}
else
{
echo "Failure.";
}
}
elseif ( $_POST['contact'] == "Mike Mason (Auction & Registration)" )
{
if ( $_POST['contact'] == "Lawrence Whittaker (Comittee Chairman)" )
{
if (mail("example@site.com", "Continuum Convention: $_POST['subject']", "$_POST['message']", "From: $_POST['name']\Reply-to: $_POST['email']"))
{
echo "Success!";
}
else
{
echo "Failure.";
}
}
else
{
echo "<b>Comittee member not recognised.</b>";
echo "<br/>";
echo "Please go back and try again.";
}
}
?>
__________________
AMW_Drizz
Dev Machine:: Apache 2.2.6 PHP 5.2.6 MySQL 5.1
|
|
|
|
11-18-2007, 12:02 PM
|
Re: Emailer code not working!
|
Posts: 462
Name: Jerod Lycett
Location: /home/arenlor
|
I am thinking there needs to be a Subject: in front of the subject for some odd reason, oh well, but in the From: and Reply-to: section and for any other headers (Cc: Bcc  you MUST have an \r\n inbetween EACH header! I'm also not sure if he needs quotes/double quotes around the message or not.
__________________
PHP Code:
<?php echo "Hello World"; ?>
HTML Code:
<html><head><title>Hello World</title></head><body><p>Hello World</p></body></html>
|
|
|
|
11-18-2007, 02:15 PM
|
Re: Emailer code not working!
|
Posts: 26
Name: Darren Driver
|
None of those are working either, I have no idea what's going on with this code >.< Here's what I've updated it to:
PHP Code:
<?php if (( $_POST['subject'] == "" ) || ( $_POST['message'] == "" ) || ( $_POST['name'] == "" ) || ( $_POST['email'] == "" )) { echo "<b>Some of the fields required have been left blank.</b>"; echo "<br/>"; echo "In order to process your request, all fields must be filled in."; } else { if ( $_POST['contact'] == "Lawrence Whittaker (Comittee Chairman)" ) { if (mail("example@site.com", "Continuum Convention: $_POST['subject']", "$_POST['message']", "From: $_POST['name']Reply-to: $_POST['email']")) { echo "Success!"; } else { echo "Failure."; } } elseif ( $_POST['contact'] == "Colin Driver (Events, Programme & Miniatures)" ) { if (mail("example@site.com", "Continuum Convention: $_POST['subject']", "$_POST['message']", "From: $_POST['name']Reply-to: $_POST['email']")) { echo "Success!"; } else { echo "Failure."; } } elseif ( $_POST['contact'] == "Simon Bray (Freeforms)" ) { if (mail("example@site.com", "Continuum Convention: $_POST['subject']", "$_POST['message']", "From: $_POST['name']Reply-to: $_POST['email']")) { echo "Success!"; } else { echo "Failure."; } } elseif ( $_POST['contact'] == "Graham Spearing (RPG, Board & Card Games)" ) { if (mail("example@site.com", "Continuum Convention: $_POST['subject']", "$_POST['message']", "From: $_POST['name']Reply-to: $_POST['email']")) { echo "Success!"; } else { echo "Failure."; } } elseif ( $_POST['contact'] == "Darran Sims (Customer Service)" ) { if (mail("example@site.com", "Continuum Convention: $_POST['subject']", "$_POST['message']", "From: $_POST['name']Reply-to: $_POST['email']")) { echo "Success!"; } else { echo "Failure."; } } elseif ( $_POST['contact'] == "Mike Mason (Auction & Registration)" ) { if (mail("example@site.com", "Continuum Convention: $_POST['subject']", "$_POST['message']", "From: $_POST['name']Reply-to: $_POST['email']")) { echo "Success!"; } else { echo "Failure."; } } else { echo "I'm sorry, I can't let you do that Darren..."; } } ?>
|
|
|
|
11-18-2007, 02:39 PM
|
Re: Emailer code not working!
|
Posts: 410
Name: Harry Burt
Location: Colchester, Essex, England
|
Hmm... I might be wrong here, but it's worth a go I think. This would how I would rewrite one of the mail functions:
PHP Code:
mail("example@site.com", "Continuum Convention: ".$_POST['subject'], $_POST['message'], "From: ".$_POST['name']."Reply-to: ".$_POST['email'])
|
|
|
|
11-18-2007, 04:12 PM
|
Re: Emailer code not working!
|
Posts: 26
Name: Darren Driver
|
I had that idea too, but no luck I'm afraid.
This is driving me bananas, I've proof read, double proof read, TRIPLE proof read and I can't see anything wrong with it!
|
|
|
|
11-18-2007, 04:41 PM
|
Re: Emailer code not working!
|
Posts: 462
Name: Jerod Lycett
Location: /home/arenlor
|
Try turning E_ALL on and see if it says something like LOL NOT HAPPENING: blank is wrong
__________________
PHP Code:
<?php echo "Hello World"; ?>
HTML Code:
<html><head><title>Hello World</title></head><body><p>Hello World</p></body></html>
|
|
|
|
11-18-2007, 06:36 PM
|
Re: Emailer code not working!
|
Posts: 26
Name: Darren Driver
|
I'm gonna ask something really dumb. How do I do that?
|
|
|
|
11-18-2007, 06:57 PM
|
Re: Emailer code not working!
|
Posts: 462
Name: Jerod Lycett
Location: /home/arenlor
|
set this error_reporting(E_ALL); after the very first of your <?php tags.
__________________
PHP Code:
<?php echo "Hello World"; ?>
HTML Code:
<html><head><title>Hello World</title></head><body><p>Hello World</p></body></html>
|
|
|
|
11-18-2007, 07:25 PM
|
Re: Emailer code not working!
|
Posts: 236
Location: London
|
I didn't really investigate what's wrong with your code, but here is my e-mail function that works 100%. The priority setting in the header is up to you.
PHP Code:
$To = "recipient@abc.com"; $Subject = "Whatever subject"; $body = "Whatever message \n\n"; $message = wordwrap($body, 70); $headers = 'From: address@site.com' . "\r\n" . 'X-Priority: 3' . "\r\n" . 'Cc: ' . "\r\n" . 'Bcc: ' . "\r\n" . 'Reply-To: address@site.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($To, $Subject, $message, $headers);
__________________
THE FORCE is with me at last! All I need now is some TALKUPATION ;)
Last edited by frofi; 11-18-2007 at 07:27 PM..
Reason: typo
|
|
|
|
11-20-2007, 02:04 PM
|
Re: Emailer code not working!
|
Posts: 26
Name: Darren Driver
|
Tried E_ALL... it came up blank. I also tried your code, frofi, but again nothing, but I might use that wordwrap code when/if it eventually works, so thanks!
|
|
|
|
11-20-2007, 03:40 PM
|
Re: Emailer code not working!
|
Posts: 26
Name: Darren Driver
|
I've come a step closer to fixing it. Turns out the code works, but the values I was putting into it were causing the problems. Any idea on how to fix this?
|
|
|
|
11-21-2007, 02:20 PM
|
Re: Emailer code not working!
|
Posts: 410
Name: Harry Burt
Location: Colchester, Essex, England
|
What worked?
What didn't?
I'm interested...
|
|
|
|
11-22-2007, 06:43 AM
|
Re: Emailer code not working!
|
Posts: 1,226
Name: Mike
Location: Mataro, Spain
|
Use phpMailer class to avoid problems with sending messages and let your recipients avoid problems with receiving them. Since such hand mailed messages are not formed properly many free mail services consider them as spam and put into corresponding folder.
|
|
|
|
|
« Reply to Emailer code not working!
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|