gmwebs Posted October 31, 2006 Share Posted October 31, 2006 Sorry... take the $ of the $echo ::) Link to comment Share on other sites More sharing options...
bufhal Posted October 31, 2006 Author Share Posted October 31, 2006 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>"; Link to comment Share on other sites More sharing options...
bufhal Posted October 31, 2006 Author Share Posted October 31, 2006 so your test worked to output the email Link to comment Share on other sites More sharing options...
gmwebs Posted October 31, 2006 Share Posted October 31, 2006 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 arrayecho "The value of email is - " . $email; //let's see what the value of $email isecho "The value of email_addr is - " . $email_addr; //let's see what the value of $email_addr isexit(); //end the script to see the outputif (!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 More sharing options...
bufhal Posted October 31, 2006 Author Share Posted October 31, 2006 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 - Link to comment Share on other sites More sharing options...
gmwebs Posted October 31, 2006 Share Posted October 31, 2006 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 arrayecho "The value of email is - " . $email; //let's see what the value of $email isecho "The value of email_addr is - " . $email_addr; //let's see what the value of $email_addr isexit(); //end the script to see the outputif (!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 More sharing options...
bufhal Posted November 1, 2006 Author Share Posted November 1, 2006 Hi gmwebs;just got back in and tried it. Still no emailsI 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 outputif (!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 More sharing options...
gmwebs Posted November 1, 2006 Share Posted November 1, 2006 So when you tried it first with the echo lines in, did it echo all the values you expected it to? Link to comment Share on other sites More sharing options...
bufhal Posted November 1, 2006 Author Share Posted November 1, 2006 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 Link to comment Share on other sites More sharing options...
gmwebs Posted November 1, 2006 Share Posted November 1, 2006 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 More sharing options...
gmwebs Posted November 1, 2006 Share Posted November 1, 2006 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. Link to comment Share on other sites More sharing options...
bufhal Posted November 1, 2006 Author Share Posted November 1, 2006 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? Link to comment Share on other sites More sharing options...
gmwebs Posted November 1, 2006 Share Posted November 1, 2006 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 More sharing options...
bufhal Posted November 1, 2006 Author Share Posted November 1, 2006 Mail with subject: This is the subject addressed to: someone.comwas succesfully sent... The body follows below. This is the message Link to comment Share on other sites More sharing options...
gmwebs Posted November 1, 2006 Share Posted November 1, 2006 I had left some test values in the previous code, but have edited it to remove them now, so this should work... Link to comment Share on other sites More sharing options...
bufhal Posted November 1, 2006 Author Share Posted November 1, 2006 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. Link to comment Share on other sites More sharing options...
gmwebs Posted November 1, 2006 Share Posted November 1, 2006 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 More sharing options...
bufhal Posted November 1, 2006 Author Share Posted November 1, 2006 SOLVED Link to comment Share on other sites More sharing options...
Recommended Posts