Jump to content

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


bufhal

Recommended Posts

Ok... so did it only echo one of the variables then? Try this and then can you post back exactly what it outputs please?
[code]
<?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>";


}
?>
[/code]
Link to comment
Share on other sites

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.

[code]
<?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>";


}
?>
[/code]
Link to comment
Share on other sites

Hi gmwebs;
just got back in and tried it. Still no emails
I commented out the lines:
[code]<?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>";
}

}
?>[/code]
Link to comment
Share on other sites

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

[code]
<?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();
}

}
?>
[/code]
Link to comment
Share on other sites

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.

[code]
<?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();
}

}
?>
[/code]
Link to comment
Share on other sites

Good to hear... I hope you didn't mind going the whole troubleshooting path with me, but I really think that this is the best way to learn. In the future, try to break your scripts up into sections and echo out the values of variables to see if you are getting what you expected. Also, don't forget to put in some form validation now, and you may wish to use one PHP script to do all of your contact functions rather than a few different ones. Just post the form to itself.

You would also benefit to have a look at some of the headers that you can send with your email, as it will allow you to define fields like "From:", "Reply To:" etc.

Would be good to mark this thread as solved too :)
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.