Automated E-mail with PHP and MySQL?

2019-06-05 05:54发布

How can I send an automated e-mail to a users entered e-mail address?

I have Xampp, which is a local web server equipped with Apache, and Mercury for mail.

Ideas?

6条回答
三岁会撩人
2楼-- · 2019-06-05 06:10

To send email: Look up the mail function.

To schedule a task in linux look up crontab.

To schedule a task in Windows look up task scheduling in the control panel.

And don't use Xampp for production. It's insecure.

查看更多
一纸荒年 Trace。
3楼-- · 2019-06-05 06:11

This is not an answer to your question, but could be relevant anyway:

My experience with a local web-server is that the mail will not get to its destination. It depends on your isp, but if you have a changing ip address every time you connect to your isp (dial-up, adsl, cable), your outgoing mail will most likely be rejected by the recipients mail server.

A lot of those ip ranges that isp give their clients are blocked by spam filters.

At least the range I am in is :)

查看更多
何必那么认真
4楼-- · 2019-06-05 06:13

Instead of php's mail() function you should use something like http://swiftmailer.org
You can easily do smtp-authentication, encryption, mime-mail, character encoding, batch mailing ...
And you get much more reliable error reporting.

查看更多
趁早两清
5楼-- · 2019-06-05 06:25

You can use phpmailer to send mail via SMTP protocol , this library is pretty good ! ( Wordpress CMS use it ! )

查看更多
\"骚年 ilove
6楼-- · 2019-06-05 06:27

php.net/mail:

mail($to, $subject, $messge);
查看更多
兄弟一词,经得起流年.
7楼-- · 2019-06-05 06:30

Be careful though, because bad people will write scripts to submit your form with a zillion email addresses and try to send spam. They will also (try) to embed \r\n in the submitted address to write out other content and headers. I do something like this:

function sanitize($s) {
  $badheaders = array("/to\:/i", "/from\:/i", "/bcc\:/i", "/cc\:/i");
  $s = preg_replace($badheaders, '(spam)', $s);
    if (strlen($s) > 2048) {
       $s = substr($s, 0, 2048);
       $s = $s." (TRUNCATED)";
    }
    return $s;
}

then I run user inputted strings through sanitize() before calling mail(). YMMV of course.

查看更多
登录 后发表回答