Jump to content

Archived

This topic is now archived and is closed to further replies.

bufhal

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

Recommended Posts

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>";

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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 -

Share this post


Link to post
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]

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites
So when you tried it first with the echo lines in, did it echo all the values you expected it to?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites
It seems as if your
[code]
<?php
if (!empty($email) && in_array($email, $emails)) {
?>
[/code]
statement is not evaluating correctly. The mail() function is never being called because it doesn't ever get there.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites
Mail with subject: This is the subject addressed to: someone.comwas succesfully sent... The body follows below.
This is the message

Share this post


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

Share this post


Link to post
Share on other sites
well Good Golly Ms. Molly  it works!!!
Thank you..it works beautifully!. I am going to study these posts and script to absorb!
Thank you very very much gmwebs! I really appreciate your help.

Share this post


Link to post
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 :)

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.

×

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.