Jump to content

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/227964-php-mail-function-using-to-or-email/
Share on other sites

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

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.