Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Emailer code not working!
Old 11-18-2007, 09:36 AM Emailer code not working!
Average Talker

Posts: 26
Name: Darren Driver
Trades: 0
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 (EventsProgramme 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 (RPGBoard 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.";
    }
  }
?>
A17roolz is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 11-18-2007, 09:47 AM Re: Emailer code not working!
Arenlor's Avatar
Ultra Talker

Posts: 462
Name: Jerod Lycett
Location: /home/arenlor
Trades: 0
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
Arenlor is offline
Reply With Quote
View Public Profile Visit Arenlor's homepage!
 
Old 11-18-2007, 11:44 AM Re: Emailer code not working!
amw_drizz's Avatar
Ultra Talker

Posts: 340
Name: Jon
Location: New York
Trades: 0
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
amw_drizz is offline
Reply With Quote
View Public Profile Visit amw_drizz's homepage!
 
Old 11-18-2007, 12:02 PM Re: Emailer code not working!
Arenlor's Avatar
Ultra Talker

Posts: 462
Name: Jerod Lycett
Location: /home/arenlor
Trades: 0
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>
Arenlor is offline
Reply With Quote
View Public Profile Visit Arenlor's homepage!
 
Old 11-18-2007, 02:15 PM Re: Emailer code not working!
Average Talker

Posts: 26
Name: Darren Driver
Trades: 0
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...";
    }
  }
?>
A17roolz is offline
Reply With Quote
View Public Profile
 
Old 11-18-2007, 02:39 PM Re: Emailer code not working!
Foundationflash's Avatar
Ultra Talker

Posts: 410
Name: Harry Burt
Location: Colchester, Essex, England
Trades: 0
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']) 
__________________
Foundation Flash tutorials :
Please login or register to view this content. Registration is FREE


New Dreamed Up Web Design:
Please login or register to view this content. Registration is FREE
Foundationflash is offline
Reply With Quote
View Public Profile Visit Foundationflash's homepage!
 
Old 11-18-2007, 04:12 PM Re: Emailer code not working!
Average Talker

Posts: 26
Name: Darren Driver
Trades: 0
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!
A17roolz is offline
Reply With Quote
View Public Profile
 
Old 11-18-2007, 04:41 PM Re: Emailer code not working!
Arenlor's Avatar
Ultra Talker

Posts: 462
Name: Jerod Lycett
Location: /home/arenlor
Trades: 0
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>
Arenlor is offline
Reply With Quote
View Public Profile Visit Arenlor's homepage!
 
Old 11-18-2007, 06:36 PM Re: Emailer code not working!
Average Talker

Posts: 26
Name: Darren Driver
Trades: 0
I'm gonna ask something really dumb. How do I do that?
A17roolz is offline
Reply With Quote
View Public Profile
 
Old 11-18-2007, 06:57 PM Re: Emailer code not working!
Arenlor's Avatar
Ultra Talker

Posts: 462
Name: Jerod Lycett
Location: /home/arenlor
Trades: 0
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>
Arenlor is offline
Reply With Quote
View Public Profile Visit Arenlor's homepage!
 
Old 11-18-2007, 07:25 PM Re: Emailer code not working!
frofi's Avatar
Extreme Talker

Posts: 236
Location: London
Trades: 0
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($body70);
$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
frofi is offline
Reply With Quote
View Public Profile
 
Old 11-20-2007, 02:04 PM Re: Emailer code not working!
Average Talker

Posts: 26
Name: Darren Driver
Trades: 0
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!
A17roolz is offline
Reply With Quote
View Public Profile
 
Old 11-20-2007, 03:40 PM Re: Emailer code not working!
Average Talker

Posts: 26
Name: Darren Driver
Trades: 0
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?
A17roolz is offline
Reply With Quote
View Public Profile
 
Old 11-21-2007, 02:20 PM Re: Emailer code not working!
Foundationflash's Avatar
Ultra Talker

Posts: 410
Name: Harry Burt
Location: Colchester, Essex, England
Trades: 0
What worked?
What didn't?
I'm interested...
__________________
Foundation Flash tutorials :
Please login or register to view this content. Registration is FREE


New Dreamed Up Web Design:
Please login or register to view this content. Registration is FREE
Foundationflash is offline
Reply With Quote
View Public Profile Visit Foundationflash's homepage!
 
Old 11-22-2007, 06:43 AM Re: Emailer code not working!
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
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.
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Reply     « Reply to Emailer code not working!
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.89428 seconds with 12 queries