HighDots Forums  

sending email using php mail()

Macromedia Dreamweaver Macromedia Dreamweaver Discussions (macromedia.dreamweaver)


Discuss sending email using php mail() in the Macromedia Dreamweaver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
awebb
 
Posts: n/a

Default sending email using php mail() - 07-14-2003 , 09:40 AM






I am successfully sending an email containing the results of a form to two
addresses BUT...
BOTH the addresses are getting TWO emails.
One has the field names like "Name: , email etc." but no other content.
The other is correctly filled out.
They always arrive in that order, i.e. empty, then correct.
My hosting company tells me my code is "incorrect" but their "help" ends
there.
The mail() code is currently in the $editFormAction block and I am wondering
if it needs to be further defined by a variable and an if or while
statement.
The php is:

/* emailing info, first set variables*/
$fname=$HTTP_POST_VARS['firstname'];
$lname=$HTTP_POST_VARS['lastname'];
$startdate1=$HTTP_POST_VARS['startdate1'];
$startdate2=$HTTP_POST_VARS['startdate2'];
$startdate3=$HTTP_POST_VARS['startdate3'];
$startdate4=$HTTP_POST_VARS['startdate4'];
$email=$HTTP_POST_VARS['email'];
$to="webmaster (AT) chinchall (DOT) com, admin (AT) chinchall (DOT) com";
$subject="Clouseau Booking";
/* The body text */
$content= "Name: ".$fname." ".$lname."\r\n"
."Week1: ".$startdate1."\r\n"
."Week2: ".$startdate2."\r\n"
."Week3: ".$startdate3."\r\n"
."Week4: ".$startdate4."\r\n"
."Email: ".$email."\r\n";
/* send the info */
mail ($to, $subject, $content);

Any ideas gratefully received.
Andy



Reply With Quote
  #2  
Old   
craig v
 
Posts: n/a

Default Re: sending email using php mail() - 07-14-2003 , 10:34 AM






It looks okay to me, but I am not a php pro...yet.

For the sake of troubleshooting, you should try doing something like this:
<***all your stuff goes here***>
$to="webmaster (AT) chinchall (DOT) com";
$to2="admin (AT) chinchall (DOT) com";
mail ($to, $subject, $content);
mail ($to2, $subject, $content);

Also, you could try this:
$to = "webmaster (AT) chinchall (DOT) com" . ", " ;
$to .= "admin (AT) chinchall (DOT) com";


Wish I could be more help.

cv


"awebb" <andywebb25 (AT) hotmail (DOT) com> wrote

I am successfully sending an email containing the results of a form to two
addresses BUT...
BOTH the addresses are getting TWO emails.
One has the field names like "Name: , email etc." but no other content.
The other is correctly filled out.
They always arrive in that order, i.e. empty, then correct.
My hosting company tells me my code is "incorrect" but their "help" ends
there.
The mail() code is currently in the $editFormAction block and I am wondering
if it needs to be further defined by a variable and an if or while
statement.
The php is:

/* emailing info, first set variables*/
$fname=$HTTP_POST_VARS['firstname'];
$lname=$HTTP_POST_VARS['lastname'];
$startdate1=$HTTP_POST_VARS['startdate1'];
$startdate2=$HTTP_POST_VARS['startdate2'];
$startdate3=$HTTP_POST_VARS['startdate3'];
$startdate4=$HTTP_POST_VARS['startdate4'];
$email=$HTTP_POST_VARS['email'];
$to="webmaster (AT) chinchall (DOT) com, admin (AT) chinchall (DOT) com";
$subject="Clouseau Booking";
/* The body text */
$content= "Name: ".$fname." ".$lname."\r\n"
."Week1: ".$startdate1."\r\n"
."Week2: ".$startdate2."\r\n"
."Week3: ".$startdate3."\r\n"
."Week4: ".$startdate4."\r\n"
."Email: ".$email."\r\n";
/* send the info */
mail ($to, $subject, $content);

Any ideas gratefully received.
Andy




Reply With Quote
  #3  
Old   
awebb
 
Posts: n/a

Default Re: sending email using php mail() - 07-14-2003 , 10:59 AM



Thanks for the tips, I'll try them though I did try in desperation the
simplest possible message,
mail ("webmaster (AT) chinchall (DOT) com", "Subject", "Message")
and that arrived twice too, though with the message "Message" in both of
them!
Its a bit of a head scratcher.
Andy
"craig v" <craig765 (AT) spamless-yahoo (DOT) com> wrote

Quote:
It looks okay to me, but I am not a php pro...yet.

For the sake of troubleshooting, you should try doing something like this:
***all your stuff goes here***
$to="webmaster (AT) chinchall (DOT) com";
$to2="admin (AT) chinchall (DOT) com";
mail ($to, $subject, $content);
mail ($to2, $subject, $content);

Also, you could try this:
$to = "webmaster (AT) chinchall (DOT) com" . ", " ;
$to .= "admin (AT) chinchall (DOT) com";


Wish I could be more help.

cv


"awebb" <andywebb25 (AT) hotmail (DOT) com> wrote in message
news:beubtt$397$1 (AT) forums (DOT) macromedia.com...
I am successfully sending an email containing the results of a form to two
addresses BUT...
BOTH the addresses are getting TWO emails.
One has the field names like "Name: , email etc." but no other content.
The other is correctly filled out.
They always arrive in that order, i.e. empty, then correct.
My hosting company tells me my code is "incorrect" but their "help" ends
there.
The mail() code is currently in the $editFormAction block and I am
wondering
if it needs to be further defined by a variable and an if or while
statement.
The php is:

/* emailing info, first set variables*/
$fname=$HTTP_POST_VARS['firstname'];
$lname=$HTTP_POST_VARS['lastname'];
$startdate1=$HTTP_POST_VARS['startdate1'];
$startdate2=$HTTP_POST_VARS['startdate2'];
$startdate3=$HTTP_POST_VARS['startdate3'];
$startdate4=$HTTP_POST_VARS['startdate4'];
$email=$HTTP_POST_VARS['email'];
$to="webmaster (AT) chinchall (DOT) com, admin (AT) chinchall (DOT) com";
$subject="Clouseau Booking";
/* The body text */
$content= "Name: ".$fname." ".$lname."\r\n"
."Week1: ".$startdate1."\r\n"
."Week2: ".$startdate2."\r\n"
."Week3: ".$startdate3."\r\n"
."Week4: ".$startdate4."\r\n"
."Email: ".$email."\r\n";
/* send the info */
mail ($to, $subject, $content);

Any ideas gratefully received.
Andy






Reply With Quote
  #4  
Old   
Joe {RoastHorse}
 
Posts: n/a

Default Re: sending email using php mail() - 07-14-2003 , 11:06 AM



as a guess i would say that your script is sending out a mail the first time
you load the page (without any vars) - then when you submit the form the
page reloads? and sends another email with the vars.

if this is the case then you need to check whether the submit button has
been clicked before executing the mail function.

eg:

if (isset ($HTTP_POST_VARS['submit'])) {
/* emailing info, first set variables*/
$fname=$HTTP_POST_VARS['firstname'];
$lname=$HTTP_POST_VARS['lastname'];
$startdate1=$HTTP_POST_VARS['startdate1'];
$startdate2=$HTTP_POST_VARS['startdate2'];
$startdate3=$HTTP_POST_VARS['startdate3'];
$startdate4=$HTTP_POST_VARS['startdate4'];
$email=$HTTP_POST_VARS['email'];
$to="webmaster (AT) chinchall (DOT) com, admin (AT) chinchall (DOT) com";
$subject="Clouseau Booking";
/* The body text */
$content= "Name: ".$fname." ".$lname."\r\n"
."Week1: ".$startdate1."\r\n"
."Week2: ".$startdate2."\r\n"
."Week3: ".$startdate3."\r\n"
."Week4: ".$startdate4."\r\n"
."Email: ".$email."\r\n";
/* send the info */
mail ($to, $subject, $content);
}

joe


"Joe {RoastHorse}" <joe (AT) roast-horse (DOT) com> wrote

Quote:
looks ok to me. what is the rest of the code?

joe



"awebb" <andywebb25 (AT) hotmail (DOT) com> wrote in message
news:beubtt$397$1 (AT) forums (DOT) macromedia.com...
I am successfully sending an email containing the results of a form to
two
addresses BUT...
BOTH the addresses are getting TWO emails.
One has the field names like "Name: , email etc." but no other content.
The other is correctly filled out.
They always arrive in that order, i.e. empty, then correct.
My hosting company tells me my code is "incorrect" but their "help" ends
there.
The mail() code is currently in the $editFormAction block and I am
wondering
if it needs to be further defined by a variable and an if or while
statement.
The php is:

/* emailing info, first set variables*/
$fname=$HTTP_POST_VARS['firstname'];
$lname=$HTTP_POST_VARS['lastname'];
$startdate1=$HTTP_POST_VARS['startdate1'];
$startdate2=$HTTP_POST_VARS['startdate2'];
$startdate3=$HTTP_POST_VARS['startdate3'];
$startdate4=$HTTP_POST_VARS['startdate4'];
$email=$HTTP_POST_VARS['email'];
$to="webmaster (AT) chinchall (DOT) com, admin (AT) chinchall (DOT) com";
$subject="Clouseau Booking";
/* The body text */
$content= "Name: ".$fname." ".$lname."\r\n"
."Week1: ".$startdate1."\r\n"
."Week2: ".$startdate2."\r\n"
."Week3: ".$startdate3."\r\n"
."Week4: ".$startdate4."\r\n"
."Email: ".$email."\r\n";
/* send the info */
mail ($to, $subject, $content);

Any ideas gratefully received.
Andy







Reply With Quote
  #5  
Old   
awebb
 
Posts: n/a

Default Re: sending email using php mail() - 07-14-2003 , 11:10 AM



Assuming you don't want the whole page, here is the code "above the page":

<?php require_once('../Connections/connChin.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "",
$theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" :
"NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue :
$theNotDefinedValue;
break;
}
return $theValue;
}

$editFormAction = $HTTP_SERVER_VARS['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING'];
}

if ((isset($HTTP_POST_VARS["MM_insert"])) && ($HTTP_POST_VARS["MM_insert"]
== "form")) {
$insertSQL = sprintf("INSERT INTO clouseau (title, firstname, lastname,
address1, address2, towncity, postcode, country, telephone, email,
startdate1, startdate2, startdate3, startdate4, totalprice, adults,
children, catering, comments) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s,
%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($HTTP_POST_VARS['title'], "text"),
GetSQLValueString($HTTP_POST_VARS['firstname'],
"text"),
GetSQLValueString($HTTP_POST_VARS['lastname'],
"text"),
GetSQLValueString($HTTP_POST_VARS['address1'],
"text"),
GetSQLValueString($HTTP_POST_VARS['address2'],
"text"),
GetSQLValueString($HTTP_POST_VARS['towncity'],
"text"),
GetSQLValueString($HTTP_POST_VARS['postcode'],
"text"),
GetSQLValueString($HTTP_POST_VARS['country'],
"text"),
GetSQLValueString($HTTP_POST_VARS['telephone'],
"text"),
GetSQLValueString($HTTP_POST_VARS['email'], "text"),
GetSQLValueString($HTTP_POST_VARS['startdate1'],
"text"),
GetSQLValueString($HTTP_POST_VARS['startdate2'],
"text"),
GetSQLValueString($HTTP_POST_VARS['startdate3'],
"text"),
GetSQLValueString($HTTP_POST_VARS['startdate4'],
"text"),
GetSQLValueString($HTTP_POST_VARS['totalprice'],
"int"),
GetSQLValueString($HTTP_POST_VARS['adults'], "int"),
GetSQLValueString($HTTP_POST_VARS['children'],
"int"),
GetSQLValueString($HTTP_POST_VARS['catering'],
"text"),
GetSQLValueString($HTTP_POST_VARS['comments'],
"text"));

mysql_select_db($database_connChin, $connChin);
$Result1 = mysql_query($insertSQL, $connChin) or die(mysql_error());

$insertGoTo =
"thanks/thankyou_clouseau.php?email=".$HTTP_POST_VARS['email']."";
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $HTTP_SERVER_VARS['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}

mysql_select_db($database_connChin, $connChin);
$query_rsClouseau = "SELECT * FROM clouseau";
$rsClouseau = mysql_query($query_rsClouseau, $connChin) or
die(mysql_error());
$row_rsClouseau = mysql_fetch_assoc($rsClouseau);
$totalRows_rsClouseau = mysql_num_rows($rsClouseau);
/* emailing info, first set variables*/
$fname=$HTTP_POST_VARS['firstname'];
$lname=$HTTP_POST_VARS['lastname'];
$startdate1=$HTTP_POST_VARS['startdate1'];
$startdate2=$HTTP_POST_VARS['startdate2'];
$startdate3=$HTTP_POST_VARS['startdate3'];
$startdate4=$HTTP_POST_VARS['startdate4'];
$email=$HTTP_POST_VARS['email'];
$to="webmaster (AT) chinchall (DOT) com, admin (AT) chinchall (DOT) com";
$subject="Clouseau Booking";
/* The body text */
$content= "Name: ".$fname." ".$lname."\r\n"
."Week1: ".$startdate1."\r\n"
."Week2: ".$startdate2."\r\n"
."Week3: ".$startdate3."\r\n"
."Week4: ".$startdate4."\r\n"
."Email: ".$email."\r\n";
/* send the info */
mail ($to, $subject, $content);
?>

As you can see, this is all created by DMX and I have just slotted in the
mail() at the bottom.
Andy

"Joe {RoastHorse}" <joe (AT) roast-horse (DOT) com> wrote

Quote:
looks ok to me. what is the rest of the code?

joe



"awebb" <andywebb25 (AT) hotmail (DOT) com> wrote in message
news:beubtt$397$1 (AT) forums (DOT) macromedia.com...
I am successfully sending an email containing the results of a form to
two
addresses BUT...
BOTH the addresses are getting TWO emails.
One has the field names like "Name: , email etc." but no other content.
The other is correctly filled out.
They always arrive in that order, i.e. empty, then correct.
My hosting company tells me my code is "incorrect" but their "help" ends
there.
The mail() code is currently in the $editFormAction block and I am
wondering
if it needs to be further defined by a variable and an if or while
statement.
The php is:

/* emailing info, first set variables*/
$fname=$HTTP_POST_VARS['firstname'];
$lname=$HTTP_POST_VARS['lastname'];
$startdate1=$HTTP_POST_VARS['startdate1'];
$startdate2=$HTTP_POST_VARS['startdate2'];
$startdate3=$HTTP_POST_VARS['startdate3'];
$startdate4=$HTTP_POST_VARS['startdate4'];
$email=$HTTP_POST_VARS['email'];
$to="webmaster (AT) chinchall (DOT) com, admin (AT) chinchall (DOT) com";
$subject="Clouseau Booking";
/* The body text */
$content= "Name: ".$fname." ".$lname."\r\n"
."Week1: ".$startdate1."\r\n"
."Week2: ".$startdate2."\r\n"
."Week3: ".$startdate3."\r\n"
."Week4: ".$startdate4."\r\n"
."Email: ".$email."\r\n";
/* send the info */
mail ($to, $subject, $content);

Any ideas gratefully received.
Andy







Reply With Quote
  #6  
Old   
Joe {RoastHorse}
 
Posts: n/a

Default Re: sending email using php mail() - 07-14-2003 , 01:10 PM



no probs.

joe




"awebb" <andywebb25 (AT) hotmail (DOT) com> wrote

Quote:
Yes,
you are right, well YOU knew that anyway, but thanks for the help.
Its much appreciated.
Andy

"Joe {RoastHorse}" <joe (AT) roast-horse (DOT) com> wrote in message
news:beuiqm$hvj$1 (AT) forums (DOT) macromedia.com...
yup - it's the scenario i described previously.
you have slotted the mail function in outside this if:

if ((isset($HTTP_POST_VARS["MM_insert"])) &&
($HTTP_POST_VARS["MM_insert"]
== "form")) {
...
}

the code within the brackets above is executed when the submit button is
clicked.
your mail function is executed every time the page loads - because it's
outside the 'if'.

joe




"awebb" <andywebb25 (AT) hotmail (DOT) com> wrote in message
news:beuh78$ekt$1 (AT) forums (DOT) macromedia.com...
Assuming you don't want the whole page, here is the code "above the
page":

?php require_once('../Connections/connChin.php'); ?
?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "",
$theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) :
$theValue;

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'"
:
"NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue :
$theNotDefinedValue;
break;
}
return $theValue;
}

$editFormAction = $HTTP_SERVER_VARS['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING'];
}

if ((isset($HTTP_POST_VARS["MM_insert"])) &&
($HTTP_POST_VARS["MM_insert"]
== "form")) {
$insertSQL = sprintf("INSERT INTO clouseau (title, firstname,
lastname,
address1, address2, towncity, postcode, country, telephone, email,
startdate1, startdate2, startdate3, startdate4, totalprice, adults,
children, catering, comments) VALUES (%s, %s, %s, %s, %s, %s, %s, %s,
%s,
%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($HTTP_POST_VARS['title'],
"text"),
GetSQLValueString($HTTP_POST_VARS['firstname'],
"text"),
GetSQLValueString($HTTP_POST_VARS['lastname'],
"text"),
GetSQLValueString($HTTP_POST_VARS['address1'],
"text"),
GetSQLValueString($HTTP_POST_VARS['address2'],
"text"),
GetSQLValueString($HTTP_POST_VARS['towncity'],
"text"),
GetSQLValueString($HTTP_POST_VARS['postcode'],
"text"),
GetSQLValueString($HTTP_POST_VARS['country'],
"text"),
GetSQLValueString($HTTP_POST_VARS['telephone'],
"text"),
GetSQLValueString($HTTP_POST_VARS['email'],
"text"),

GetSQLValueString($HTTP_POST_VARS['startdate1'],
"text"),

GetSQLValueString($HTTP_POST_VARS['startdate2'],
"text"),

GetSQLValueString($HTTP_POST_VARS['startdate3'],
"text"),

GetSQLValueString($HTTP_POST_VARS['startdate4'],
"text"),

GetSQLValueString($HTTP_POST_VARS['totalprice'],
"int"),
GetSQLValueString($HTTP_POST_VARS['adults'],
"int"),
GetSQLValueString($HTTP_POST_VARS['children'],
"int"),
GetSQLValueString($HTTP_POST_VARS['catering'],
"text"),
GetSQLValueString($HTTP_POST_VARS['comments'],
"text"));

mysql_select_db($database_connChin, $connChin);
$Result1 = mysql_query($insertSQL, $connChin) or die(mysql_error());

$insertGoTo =
"thanks/thankyou_clouseau.php?email=".$HTTP_POST_VARS['email']."";
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $HTTP_SERVER_VARS['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}

mysql_select_db($database_connChin, $connChin);
$query_rsClouseau = "SELECT * FROM clouseau";
$rsClouseau = mysql_query($query_rsClouseau, $connChin) or
die(mysql_error());
$row_rsClouseau = mysql_fetch_assoc($rsClouseau);
$totalRows_rsClouseau = mysql_num_rows($rsClouseau);
/* emailing info, first set variables*/
$fname=$HTTP_POST_VARS['firstname'];
$lname=$HTTP_POST_VARS['lastname'];
$startdate1=$HTTP_POST_VARS['startdate1'];
$startdate2=$HTTP_POST_VARS['startdate2'];
$startdate3=$HTTP_POST_VARS['startdate3'];
$startdate4=$HTTP_POST_VARS['startdate4'];
$email=$HTTP_POST_VARS['email'];
$to="webmaster (AT) chinchall (DOT) com, admin (AT) chinchall (DOT) com";
$subject="Clouseau Booking";
/* The body text */
$content= "Name: ".$fname." ".$lname."\r\n"
."Week1: ".$startdate1."\r\n"
."Week2: ".$startdate2."\r\n"
."Week3: ".$startdate3."\r\n"
."Week4: ".$startdate4."\r\n"
."Email: ".$email."\r\n";
/* send the info */
mail ($to, $subject, $content);
?

As you can see, this is all created by DMX and I have just slotted in
the
mail() at the bottom.
Andy

"Joe {RoastHorse}" <joe (AT) roast-horse (DOT) com> wrote in message
news:beuglv$dep$1 (AT) forums (DOT) macromedia.com...
looks ok to me. what is the rest of the code?

joe



"awebb" <andywebb25 (AT) hotmail (DOT) com> wrote in message
news:beubtt$397$1 (AT) forums (DOT) macromedia.com...
I am successfully sending an email containing the results of a
form
to
two
addresses BUT...
BOTH the addresses are getting TWO emails.
One has the field names like "Name: , email etc." but no other
content.
The other is correctly filled out.
They always arrive in that order, i.e. empty, then correct.
My hosting company tells me my code is "incorrect" but their
"help"
ends
there.
The mail() code is currently in the $editFormAction block and I am
wondering
if it needs to be further defined by a variable and an if or while
statement.
The php is:

/* emailing info, first set variables*/
$fname=$HTTP_POST_VARS['firstname'];
$lname=$HTTP_POST_VARS['lastname'];
$startdate1=$HTTP_POST_VARS['startdate1'];
$startdate2=$HTTP_POST_VARS['startdate2'];
$startdate3=$HTTP_POST_VARS['startdate3'];
$startdate4=$HTTP_POST_VARS['startdate4'];
$email=$HTTP_POST_VARS['email'];
$to="webmaster (AT) chinchall (DOT) com, admin (AT) chinchall (DOT) com";
$subject="Clouseau Booking";
/* The body text */
$content= "Name: ".$fname." ".$lname."\r\n"
."Week1: ".$startdate1."\r\n"
."Week2: ".$startdate2."\r\n"
."Week3: ".$startdate3."\r\n"
."Week4: ".$startdate4."\r\n"
."Email: ".$email."\r\n";
/* send the info */
mail ($to, $subject, $content);

Any ideas gratefully received.
Andy













Reply With Quote
Reply




Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.