php mail()函数代码将电子邮件发送一次到特定的电子邮件地址

时间:2018-11-30 09:38:40

标签: php email

简单的php mail()函数代码可以测试我网站上的邮件,但只发送了一次邮件,请问我做错了什么?

<?php
    ini_set( 'display_errors', 1 );
    error_reporting( E_ALL );
    $from = "info@companyemail.com";
    $to = "mypersonal@gmail.com";
    $subject = "Checking PHP mail";
    $message = "The PHP mail works just fine you should see it in your inbox";
    $headers = "From:" . $from;
    mail($to,$subject,$message, $headers);
    echo "The email message was sent.";
?>

1 个答案:

答案 0 :(得分:0)

这里您需要在while循环中添加条件,请看下面的代码。

$i = 0;
while ($i < 10) //provide as many as mail are you sending,like it will sends 10 times.
{ 
    ini_set( 'display_errors', 1 );
    error_reporting( E_ALL );
    $from = "info@severnfundingninvestment.com";
    $to = "ogukingsley@gmail.com";
    $subject = "Checking PHP mail";
    $message = "The PHP mail works just fine you should see it in your inbox";
    $headers = "From:" . $from; mail($to,$subject,$message, $headers);
    echo "The email message was sent.";
    $i = $i + 1;
}