wright67uk Posted February 17, 2011 Share Posted February 17, 2011 Please would somebody be able to show me or give me some tips as to how I go about getting an email to send in my php code? $headers = 'From: me@me.com' . "\r\n" . 'Reply-To: me@me.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); $first = $_GET['first']; $last = $_GET['last']; $town = $_GET['town']; $telephone = $_GET['telephone']; $code = $_GET['postcode']; $shortcode = substr($code,0,2); $query =mysql_query ("SELECT email FROM treesurgeons WHERE postcode like '%" . $shortcode . "%' ORDER BY companyName LIMIT 3"); echo mysql_error(); echo "<p>The email addresses you have requested are;</p>"; while($ntx=mysql_fetch_row($query)) $nt[] = $ntx[0]; echo "$nt[0]<br>$nt[1]<br>$nt[2]<br>"; $message = "$first . $last, from $town has searched for your details.<br>You may contact them on $telephone. <br> Thankyou."; $subject = "You Showed Up In The Tree Directory!"; $email = "$nt[0],$nt[1],$nt[2]"; $to = "$email"; mail( "$to", "$subject","$message", "$headers"); ?></body></html> Quote Link to comment https://forums.phpfreaks.com/topic/227964-php-mail-function-using-to-or-email/ Share on other sites More sharing options...
cgsmith105 Posted February 17, 2011 Share Posted February 17, 2011 Hi wright67uk, I am wondering what you are trying to do and what the end result is. It seems that the code is quite busy and needs to be broken into sections to really figure out where something is going wrong. Are you receiving any errors in the code? For example... some of your code could look like this near the end: $toEmail = "$nt[0],$nt[1],$nt[2]"; mail( $toEmail, $subject,$message, $headers); The mail() depends on how your email is setup on the server itself (through Apache or what have you). Here is an example of an email form I use for an old "Contact Us" form (understand this has NO validation!): $Name = $_POST['FirstName'] . " ".$_POST['LastName']; $Phone = $_POST['PAreaCode'] . "-" . $_POST['PPrefix'] . "-" .$_POST['PSuffix']; $Email = $_POST['Email']; $Cmnts = $_POST['Comments']; $to = "sales@email.com" . ", "; $subject = "You have a new lead!"; $body = "Here is ".$Name."'s contact information:<br/> Name: ".$Name."<br/> Phone: ".$Phone."<br/> Email: ".$Email."<br/> Comments: ".$Cmnts; $headers = 'MIME-Version: 1.0' . "\r\n" . 'Content-type: text/html; charset=iso-8859-1' . "\r\n" . 'From: sales@email.com' . "\r\n" . 'Reply-To: sales@email.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $body); echo "<h2>Thank you $Name!</h2><p>Someone will be in touch with you within the next business day! Below is the information we are receiving: </p><p>$body</p><br/><br/><br/>"; Quote Link to comment https://forums.phpfreaks.com/topic/227964-php-mail-function-using-to-or-email/#findComment-1175501 Share on other sites More sharing options...
denno020 Posted February 17, 2011 Share Posted February 17, 2011 Remove the double quotes around $email when you assign it to $to. This is how you want it: $to = $email; As for anything else, you're going to have to give more information as to what you actually want, and what you're having problems with. Denno Quote Link to comment https://forums.phpfreaks.com/topic/227964-php-mail-function-using-to-or-email/#findComment-1175539 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.