Learning diary,send email using PHP,学习笔记,用php send email

in #php7 years ago (edited)

Screen Shot 2018-03-01 at 9.28.12 PM.png

Hello Steemit friends, today I just want to send email using PHP, I never thought it would be so difficult because it is supposed to be a simple thing, below is how to install PHPMailer
今天想用php send email这么简单的东西竟然要用掉半天,因为php send email主要是要用PHPMailer,而install的方式竟然是以下这样而已

composer require phpmailer/phpmailer

But of course we need to SSH into the server first and enter the above install code, then we can create a simple php file such as test_email.php and test to send out one email
不过当然是要SSH进入server先,然后就可以随便开一个test_email.php然后试看send email

官网
https://github.com/PHPMailer/PHPMailer

 $mail->SMTPDebug = 2;                                 // Enable verbose debug output
    $mail->isSMTP();                                      // Set mailer to use SMTP
    $mail->Host = 'smtp1.example.com;smtp2.example.com';  // Specify main and backup SMTP servers
    $mail->SMTPAuth = true;                               // Enable SMTP authentication
    $mail->Username = '[email protected]';                 // SMTP username
    $mail->Password = 'secret';                           // SMTP password
    $mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 587;                                    // TCP port to connect to

Above is the setting provided by the github saying we should key in the smtp, username, password, port to send out the email, but after taking half day trying, it just keep failing, seem like everything given by the godaddy sharehosting is incorrect, i have tried so many type of IP, SMTP, port all fail, then finally I used the most unusual setting to send out my email which as below

不过做了半天就是email send不出去,主要是我用godaddy sharehosting,几乎里面给的cpanel email的IP和SMTP和port都不对,最后用以下的奇葩setting才send的出去

$mail->Host = 'localhost';
$mail->Port = 25;
$mail->SMTPSecure = false;
$mail->SMTPAutoTLS = false;
$mail->SMTPAuth = false;     

the Host is localhost and port is 25, other stuff all put as false only I can sent out the email, I also dunno why, thanks for reading
IP 竟然放localhost, 然后port竟然要放25,然后其他东西关完才能send出去,真搞不懂为什么

谢谢阅读

Sort:  

新年快乐!cn区点赞机器人 @cnbuddy 感谢你对cn区作出成长的贡献。如果我打扰到你,请回复“取消”。

Coin Marketplace

STEEM 0.18
TRX 0.15
JST 0.029
BTC 63607.88
ETH 2506.13
USDT 1.00
SBD 2.59