Jump to content


Photo

multiple website emails, one form for customers for all emails?


  • This topic is locked This topic is locked
42 replies to this topic

#21 bufhal

bufhal
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts

Posted 31 October 2006 - 01:27 PM

absolutely, I appreciate your help.
Throughout our website there soon to be multiple email gif links that, when clicked, will bring up the form page mail4.php. The link goes to the mail4.php page but thats all it does. It should recognise a variable in the array. As of now, when someone clicks the form submit, it is going to the mail2.php elseif, which I thought I correctly fixed(It had my email in it and I would recieve the form results, however, it should not reach the elseif statement if working correctly and someone fills out both form fields.
I know this is overly complicated but the whole idea is to have the 50-70 emails on our site replaced with gif's which will offer the form.
Thank you, I hope this clarifies somewhat. I am learning on the fly mand appreciate your help and patience.

#22 gmwebs

gmwebs
  • Members
  • PipPipPip
  • Advanced Member
  • 174 posts
  • LocationLondon

Posted 31 October 2006 - 03:04 PM

Ok, so in mail4.php we need to retrieve the value from the gif and assign it to a hidden value in the form.

<?php

$email = $_GET['email_to']; //Get the value of the email_to variable in the gif. Might need to use $HTTP_GET_VARS instead of $_GET but try this first

?>
<form action="mail2.php" method="POST"> 
   <input type="hidden" name="email" value="<?php echo $email; ?>">
<p><b>Subject</b><br> 
   <input type="text" name="subject" size=50> 
   <br><br> 
<b>Message</b><br> 
<textarea cols=40 rows=10 name="message"></textarea><br><br>
<input type="submit" value=" Send "> 
</form>

And I am pretty sure that you need to move the email array in this file to mail2.php. The idea is that the hidden value is sent to mail2.php, and then it finds the email address based on what this value is.

#23 bufhal

bufhal
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts

Posted 31 October 2006 - 07:56 PM

Thank you for hanging in there with me.  Still not sending email. Here is what I have for the three files.
have this for link:

E-mail:
<a href="mail4.php?email_to=mkt"><img src="images/Ed_email.gif" width="152" height="14" border="0"></a>
mail4.php:
<?php
$email = $HTTP_GET_VARS['email_to']; 
//Get the value of the email_to variable in the gif. Might need to use $HTTP_GET_VARS instead of $_GET but try this first
?>
<form action="mail2.php" method="POST"> 
   <input type="hidden" name="email" value="<?php echo $email; ?>">
<p><b>Subject</b><br> 
   <input type="text" name="subject" size=50> 
   <br><br> 
<b>Message</b><br> 
<textarea cols=40 rows=10 name="message"></textarea><br><br>
<input type="submit" value=" Send "> 
</form>
<br><br>
<hr>
</body></center> 
</html>


mail2.php:

<?php
$emails = array(
'mkt' => 'mkt@tech.com',
'dd' => 'dd@email.com',
'rpec' => 'gz@tech.com',
'gz' => 'mkt@tech.com'
);
if (!empty($_GET['email_to']) && in_array($_GET['email_to'], $emails)) {

   if (mail(  )) { 
      echo 'Email sent'; 
      exit(); 
   } 
}
?> 
<?php

/* All form fields are automatically passed to the PHP script through the array $HTTP_POST_VARS. */
$email = $HTTP_POST_VARS['email'];
$subject = $HTTP_POST_VARS['subject'];
$message = $HTTP_POST_VARS['message'];

/* PHP form validation: the script checks that the Email field contains a valid email address and the Subject field isn't empty. preg_match performs a regular expression match. It's a very powerful PHP function to validate form fields and other strings - see PHP manual for details. */
if ($subject == "") {
  echo "<h4>No subject</h4>";
  echo "<a href='javascript:history.back(1);'>Back</a>";
}

/* Sends the mail and outputs the "Thank you" string if the mail is successfully sent, or the error string otherwise. */
 elseif (mail($email,$subject,$message)) {
 echo "<h3>Thank you for sending email</h3>";
} else {
  echo "<h4>Can't send email to $email</h4>";
}
?> 


#24 gmwebs

gmwebs
  • Members
  • PipPipPip
  • Advanced Member
  • 174 posts
  • LocationLondon

Posted 31 October 2006 - 08:14 PM

<?php
$emails = array(
'mkt' => 'mkt@attotech.com',
'dd' => 'dd@email.com',
'rpec' => 'gzakes@attotech.com',
'gz' => 'mkt@attotech.com'
);

$email = $HTTP_POST_VARS['email'];

echo $email; //let's see what the value of $email is

if (!empty($email) && in_array($email, $emails)) {

/* All form fields are automatically passed to the PHP script through the array $HTTP_POST_VARS. */
$email_addr = $emails['email'];
$subject = $HTTP_POST_VARS['subject'];
$message = $HTTP_POST_VARS['message'];

$echo $email_addr; //let's see what the value of $email_addr is
exit(); //end the script to see the output

/* PHP form validation: the script checks that the Email field contains a valid email address and the Subject field isn't empty. preg_match performs a regular expression match. It's a very powerful PHP function to validate form fields and other strings - see PHP manual for details. */
if ($subject == "") {
  echo "<h4>No subject</h4>";
  echo "<a href='javascript:history.back(1);'>Back</a>";
}

/* Sends the mail and outputs the "Thank you" string if the mail is successfully sent, or the error string otherwise. */
 elseif (mail($email_addr,$subject,$message)) {
 echo "<h3>Thank you for sending email</h3>";
} else {
  echo "<h4>Can't send email to $email</h4>";
}   

}
?> 


#25 bufhal

bufhal
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts

Posted 31 October 2006 - 08:29 PM

getting a parse error:
Parse error: parse error, unexpected T_VARIABLE in /home/attonet/www/atto.net/mail2.php on line 311

307  /* All form fields are automatically passed to the PHP script through the array
308  $HTTP_POST_VARS. */
309  $email_addr = $emails['email'];
310  $subject = $HTTP_POST_VARS['subject'];
311  $message = $HTTP_POST_VARS['message'];

$echo $email_addr; //let's see what the value of $email_addr is
exit(); //end the script to see the output

#26 gmwebs

gmwebs
  • Members
  • PipPipPip
  • Advanced Member
  • 174 posts
  • LocationLondon

Posted 31 October 2006 - 08:33 PM

Sorry... take the $ of the $echo  ::)

#27 bufhal

bufhal
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts

Posted 31 October 2006 - 09:03 PM

Hi;
I took the $ variable off echo. When I now submit, no email is sent and the mail2.php page shows "mkt" intead of
echo "<h3>Thank you for sending email</h3>";


#28 bufhal

bufhal
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts

Posted 31 October 2006 - 09:07 PM

so your test worked to output the email

#29 gmwebs

gmwebs
  • Members
  • PipPipPip
  • Advanced Member
  • 174 posts
  • LocationLondon

Posted 31 October 2006 - 09:15 PM

Ok... so did it only echo one of the variables then? Try this and then can you post back exactly what it outputs please?
<?php
$emails = array(
'mkt' => 'mkt@attotech.com',
'dd' => 'dd@email.com',
'rpec' => 'gzakes@attotech.com',
'gz' => 'mkt@attotech.com'
);

$email = $HTTP_POST_VARS['email'];
$email_addr = $emails['email'];

print_r($emails); //echo the value of the array

echo "The value of email is - " . $email; //let's see what the value of $email is
echo "The value of email_addr is - " . $email_addr; //let's see what the value of $email_addr is

exit(); //end the script to see the output

if (!empty($email) && in_array($email, $emails)) {

/* All form fields are automatically passed to the PHP script through the array $HTTP_POST_VARS. */
$subject = $HTTP_POST_VARS['subject'];
$message = $HTTP_POST_VARS['message'];

/* PHP form validation: the script checks that the Email field contains a valid email address and the Subject field isn't empty. preg_match performs a regular expression match. It's a very powerful PHP function to validate form fields and other strings - see PHP manual for details. */
if ($subject == "") {
  echo "<h4>No subject</h4>";
  echo "<a href='javascript:history.back(1);'>Back</a>";
}

/* Sends the mail and outputs the "Thank you" string if the mail is successfully sent, or the error string otherwise. */
 elseif (mail($email_addr,$subject,$message)) {
 echo "<h3>Thank you for sending email</h3>";
} else {
  echo "<h4>Can't send email to $email</h4>";
}   

}
?> 


#30 bufhal

bufhal
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts

Posted 31 October 2006 - 09:22 PM

Array ( [mkt] => mkt@tech.com [dd] => dd@email.com [rpec] => gz@tech.com [gz] => mkt@tech.com ) The value of email is - mktThe value of email_addr is -

#31 gmwebs

gmwebs
  • Members
  • PipPipPip
  • Advanced Member
  • 174 posts
  • LocationLondon

Posted 31 October 2006 - 10:48 PM

Sorry Bufhal! I was doing too many things at the same time, and made a stupid mistake... $email_addr = $emails['emails]; should have been $email_addr = $emails[$email]; Try this and let's see if the email address is now echo'ed. If it is, then remove the echo statements and the exit(); and see if it emails now.

<?php
$emails = array(
'mkt' => 'mkt@attotech.com',
'dd' => 'dd@email.com',
'rpec' => 'gzakes@attotech.com',
'gz' => 'mkt@attotech.com'
);

$email = $HTTP_POST_VARS['email'];
$email_addr = $emails[$email]; //See? We need to find the email address that $email refers to in the array...

print_r($emails); //echo the value of the array

echo "The value of email is - " . $email; //let's see what the value of $email is
echo "The value of email_addr is - " . $email_addr; //let's see what the value of $email_addr is

exit(); //end the script to see the output

if (!empty($email) && in_array($email, $emails)) {

/* All form fields are automatically passed to the PHP script through the array $HTTP_POST_VARS. */
$subject = $HTTP_POST_VARS['subject'];
$message = $HTTP_POST_VARS['message'];

/* PHP form validation: the script checks that the Email field contains a valid email address and the Subject field isn't empty. preg_match performs a regular expression match. It's a very powerful PHP function to validate form fields and other strings - see PHP manual for details. */
if ($subject == "") {
  echo "<h4>No subject</h4>";
  echo "<a href='javascript:history.back(1);'>Back</a>";
}

/* Sends the mail and outputs the "Thank you" string if the mail is successfully sent, or the error string otherwise. */
 elseif (mail($email_addr,$subject,$message)) {
 echo "<h3>Thank you for sending email</h3>";
} else {
  echo "<h4>Can't send email to $email</h4>";
}   

}
?>


#32 bufhal

bufhal
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts

Posted 01 November 2006 - 02:08 PM

Hi gmwebs;
just got back in and tried it. Still no emails
I commented out the lines:
<?php
$emails = array(
'mkt' => 'mkt@attotech.com',
'dd' => 'dd@email.com',
'rpec' => 'gzakes@attotech.com',
'gz' => 'mkt@attotech.com'
);

$email = $HTTP_POST_VARS['email'];
$email_addr = $emails[$email]; //See? We need to find the email address that $email refers to in the array...

//print_r($emails); //echo the value of the array

//echo "The value of email is - " . $email; //let's see what the value of $email is
//echo "The value of email_addr is - " . $email_addr; //let's see what the value of $email_addr is

//exit(); //end the script to see the output

if (!empty($email) && in_array($email, $emails)) {

/* All form fields are automatically passed to the PHP script through the array $HTTP_POST_VARS. */
$subject = $HTTP_POST_VARS['subject'];
$message = $HTTP_POST_VARS['message'];

/* PHP form validation: the script checks that the Email field contains a valid email address and the Subject field isn't empty. preg_match performs a regular expression match. It's a very powerful PHP function to validate form fields and other strings - see PHP manual for details. */
if ($subject == "") {
echo "<h4>No subject</h4>";
echo "<a href='javascript:history.back(1);'>Back</a>";
}

/* Sends the mail and outputs the "Thank you" string if the mail is successfully sent, or the error string otherwise. */
elseif (mail($email_addr,$subject,$message)) {
echo "<h3>Thank you for sending email</h3>";
} else {
echo "<h4>Can't send email to $email</h4>";
} 

}
?>


#33 gmwebs

gmwebs
  • Members
  • PipPipPip
  • Advanced Member
  • 174 posts
  • LocationLondon

Posted 01 November 2006 - 02:21 PM

So when you tried it first with the echo lines in, did it echo all the values you expected it to?

#34 bufhal

bufhal
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts

Posted 01 November 2006 - 02:22 PM

yesy it did:
Array ( [mkt] => mkt@attotech.com [dd] => dd@email.com [rpec] => gzakes@attotech.com [gz] => mkt@attotech.com ) The value of email is - mktThe value of email_addr is - mkt@attotech.com

#35 gmwebs

gmwebs
  • Members
  • PipPipPip
  • Advanced Member
  • 174 posts
  • LocationLondon

Posted 01 November 2006 - 02:30 PM

Let's remove your validation, and just see if the actual mechanism logic is correct...

<?php
$emails = array(
'mkt' => 'mkt@attotech.com',
'dd' => 'dd@email.com',
'rpec' => 'gzakes@attotech.com',
'gz' => 'mkt@attotech.com'
);

$email = $HTTP_POST_VARS['email'];
$email_addr = $emails[$email]; //See? We need to find the email address that $email refers to in the array...

if (!empty($email) && in_array($email, $emails)) {

	/* All form fields are automatically passed to the PHP script through the array $HTTP_POST_VARS. */
	$subject = $HTTP_POST_VARS['subject'];
	$message = $HTTP_POST_VARS['message'];

	if (mail($email_addr,$subject,$message)) { //If mail() returns TRUE
		echo "Mail with subject: " . $subject ." addressed to: " . $email_addr . " was succesfully sent... The body follows below. <br />" . $message ;
		exit();
	} else { //If mail() returns FALSE
		echo "Mail with subject: " . $subject ." addressed to: " . $email_addr . " was NOT sent succesfully ... The body follows below. <br />" . $message ;
		exit();
	}
	
}
?>


#36 gmwebs

gmwebs
  • Members
  • PipPipPip
  • Advanced Member
  • 174 posts
  • LocationLondon

Posted 01 November 2006 - 02:43 PM

It seems as if your
<?php 
if (!empty($email) && in_array($email, $emails)) { 
?>

statement is not evaluating correctly. The mail() function is never being called because it doesn't ever get there.

#37 bufhal

bufhal
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts

Posted 01 November 2006 - 02:51 PM

whould that be caused by the original link:
E-mail: <a href="mail4.php?email_to=mkt"><img src="images/Ed_email.gif" width="152" height="14" border="0"></a>

It goes to the right page but not passing the correct value?

#38 gmwebs

gmwebs
  • Members
  • PipPipPip
  • Advanced Member
  • 174 posts
  • LocationLondon

Posted 01 November 2006 - 02:53 PM

Ok, you were using the wrong array search function... You have keys in your array, so you will need to see if the key exists.

<?php
$emails = array(
'mkt' => 'mkt@attotech.com',
'dd' => 'dd@email.com',
'rpec' => 'gzakes@attotech.com',
'gz' => 'mkt@attotech.com'
);

$email = $HTTP_POST_VARS['email'];
$email_addr = $emails[$email]; //See? We need to find the email address that $email refers to in the array...

if (!empty($email) && array_key_exists($email, $emails)) {

	/* All form fields are automatically passed to the PHP script through the array $HTTP_POST_VARS. */
	$subject = $HTTP_POST_VARS['subject'];
	$message = $HTTP_POST_VARS['message'];

	if (mail($email_addr,$subject,$message)) { //If mail() returns TRUE
		echo "Mail with subject: " . $subject ." addressed to: " . $email_addr . " was succesfully sent... The body follows below. <br />" . $message ;
		exit();
	} else { //If mail() returns FALSE
		echo "Mail with subject: " . $subject ." addressed to: " . $email_addr . " was NOT sent succesfully ... The body follows below. <br />" . $message ;
		exit();
	}
	
}
?>


#39 bufhal

bufhal
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts

Posted 01 November 2006 - 03:15 PM

Mail with subject: This is the subject addressed to: someone.comwas succesfully sent... The body follows below.
This is the message

#40 gmwebs

gmwebs
  • Members
  • PipPipPip
  • Advanced Member
  • 174 posts
  • LocationLondon

Posted 01 November 2006 - 03:23 PM

I had left some test values in the previous code, but have edited it to remove them now, so this should work...




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users