简体   繁体   English

发送电子邮件到MYSQL地址

[英]send email to address on MYSQL

I have a MySQL DB with EMAIL row. 我有一个带有EMAIL行的MySQL数据库。
User perform a search and the relevant info comes up in a <table> format (address 1, address 2, phone, fax, email, etc). 用户执行搜索,相关信息以<table>格式显示(地址1,地址2,电话,传真,电子邮件等)。
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. <tabel> ,最后一列具有“电子邮件”按钮,如果单击它,系统应将自动电子邮件发送到该电子邮件地址。

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. 如何修改此php以仅将电子邮件发送到该特定行。

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? 向其添加/替换向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??? 通过此代码发送到我的gmail帐户的电子邮件时,我可以看到发件人是:“ webmaster@example.com ip-XXX-XXX-XXX-XXX.yyyyyyyyyyy.zzzz.net”(这是我服务器的IP)...为什么看起来像那样???

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?; 1:向其添加/替换哪些内容以将电子邮件发送到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??? 2:当此代码将电子邮件发送到我的gmail帐户时,我可以看到发件人是:“ webmaster@example.com ip-XXX-XXX-XXX-XXX.yyyyyyyyyyy.zzzz.net”(这是我的服务器的IP)。 ...为什么看起来像那样???

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 为此,请单击链接: 从root @ servername更改传出邮件地址-rackspace sendgrid postfix

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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