Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 随机密码生成和发送电子邮件_Php_Email - Fatal编程技术网

Php 随机密码生成和发送电子邮件

Php 随机密码生成和发送电子邮件,php,email,Php,Email,我想在表单中输入电子邮件和公司名称,然后必须向给定的电子邮件发送随机生成的密码 下面是我生成随机密码和发送电子邮件的代码 <?php $company_name = ""; $email = ""; if (isset($_POST['submit'])) { $company_name = $_POST["company_name"]; $email = $_POST["email_address"]; $chars = "abcdefghijklmnopqrs

我想在表单中输入电子邮件和公司名称,然后必须向给定的电子邮件发送随机生成的密码

下面是我生成随机密码和发送电子邮件的代码

<?php

$company_name = "";
$email = "";
if (isset($_POST['submit'])) {
    $company_name = $_POST["company_name"];
    $email = $_POST["email_address"];
    $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%&*_";
    $password = substr(str_shuffle($chars), 0, 8);
    $to = $email;
    $subject = 'your registration is completed';
    $message = 'Welcome' . $company_name . ''
            . 'Your email and password is following :'
            . 'Email:' . $email . ''
            . 'Your new password : ' . $password . ''
            . 'Now you can login with this email and password';
    $headers = 'From :' . $email . "\r\n";
    mail($to, $subject, $message, $headers);
}
?>

但这显示了下面的错误

警告:mail()[function.mail]:“sendmail\u from”未在php.ini中设置,或“custom”from:“path”\password\u generation.php第21行缺少标题

第21行是
邮件($to、$subject、$message、$headers)

试试这个

 <?php

    $company_name = "";
    $email = "";
    if (isset($_POST['submit'])) {
        $company_name = $_POST["company_name"];
        $email = $_POST["email_address"];
        $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%&*_";
        $password = substr(str_shuffle($chars), 0, 8);
        $to = $email;
        $subject = 'your registration is completed';
        $message = 'Welcome' . $company_name . ''
                . 'Your email and password is following :'
                . 'Email:' . $email . ''
                . 'Your new password : ' . $password . ''
                . 'Now you can login with this email and password';
        $headers = 'From: Your name <'.$email .'>' . "\r\n";
        $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 

        mail($to, $subject, $message, $headers);
    }
    ?>

试试这个

 <?php

    $company_name = "";
    $email = "";
    if (isset($_POST['submit'])) {
        $company_name = $_POST["company_name"];
        $email = $_POST["email_address"];
        $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%&*_";
        $password = substr(str_shuffle($chars), 0, 8);
        $to = $email;
        $subject = 'your registration is completed';
        $message = 'Welcome' . $company_name . ''
                . 'Your email and password is following :'
                . 'Email:' . $email . ''
                . 'Your new password : ' . $password . ''
                . 'Now you can login with this email and password';
        $headers = 'From: Your name <'.$email .'>' . "\r\n";
        $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 

        mail($to, $subject, $message, $headers);
    }
    ?>


检查此项:@Amine Soumiaa它工作正常,但现在显示此错误
警告:mail()[function.mail]:无法在“127.0.0.1”端口25连接到mailserver,请验证php.ini中的“SMTP”和“SMTP\u port”设置,或在第23行的“path”password\u generation.php中使用ini\u set()
检查此项以了解stmp问题(第一个解决方案):检查此项:@Amine Soumiaa它工作了,但现在显示此错误
警告:mail()[function.mail]:无法在“127.0.0.1”端口25连接到mailserver,请验证php.ini中的“SMTP”和“SMTP_port”设置,或在第23行的“path”password_generation.php中使用ini_set()
检查此项以了解stmp问题(第一个解决方案):
警告:mail()[function.mail]:无法在“127.0.0.1”端口25连接到mailserver,请验证php.ini中的“SMTP”和“SMTP_port”设置,或在第23行的“path”password_generation.php中使用ini_set()
现在此错误显示为@Manjeet Barnalaby default,php将尝试通过本地SMTP服务器发送,这就是显示此警告的原因,您需要做的是编辑php.ini文件,找到SMTP选项并使用SMTP服务器进行更改,或者尝试将此文件上载到联机服务器并测试电子邮件功能,这将联机工作…
warning:mail()[function.mail]:无法在“127.0.0.1”端口25连接到邮件服务器,请验证您的“SMTP”和php.ini中的“smtp_port”设置,或在第23行的“path”password_generation.php中使用ini_set()
现在此错误显示为@Manjeet Barnalaby default,php将尝试通过本地smtp服务器发送,这就是为什么显示此警告,您需要做的是编辑您的php.ini文件,并找到SMTP选项,用SMTP服务器更改它,或者尝试将此文件上载到联机服务器并测试电子邮件功能,这将联机工作。。。