简体   繁体   中英

send email to address on MYSQL

I have a MySQL DB with EMAIL row.
User perform a search and the relevant info comes up in a <table> format (address 1, address 2, phone, fax, email, etc).
In the <tabel> , the last column has an "E-mail" button and if you click it the system should send an automated email to that email address.

I have found one article here which actually works for me, but it send email to everyone in the DB. How can I modify this php to send email to ONLY that specific row.

Here is what I found:

mysql_connect('localhost', 'mysql_user', 'mysql_password') or
    die("Could not connect: " . mysql_error());
mysql_select_db("mydb");

$result = mysql_query("SELECT email FROM mytable");

while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
    sendMail($row[0]);
}
mysql_free_result($result);

function sendMail($to){
$subject = 'AC the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
  'Reply-To: webmaster@example.com' . "\r\n" .
  'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
  1. What to add/replace to it to send email to individual row in DB TABLE?
  2. when the email sent by this code to my gmail account i can see the sender is: "webmaster@example.com ip-XXX-XXX-XXX-XXX.yyyyyyyyyyy.zzzz.net" (which is my server's IP).... WHY does it appear like that???

I have added to this code the following to see if it picks up the right records (which it does):

  mail($to, $subject, $message, $headers);

      echo 'email has been sent to: ' . $to . '<br/>';
  }

after email sent, it list the email addresses back to me and all email addresses receives the email...

I would appreciate your help!

1: What to add/replace to it to send email to individual row in DB TABLE?; you can add conditional query to fetch particular user's email like :

SELECT email FROM mytable where <your condition>

2: when the email sent by this code to my gmail account i can see the sender is: "webmaster@example.com ip-XXX-XXX-XXX-XXX.yyyyyyyyyyy.zzzz.net" (which is my server's IP).... WHY does it appear like that???

by default it shows the server default email address, you can update it also. To do so, follow the link : Change outgoing mail address from root@servername - rackspace sendgrid postfix

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM