【问题标题】:Random password generation and sending a email随机密码生成和发送电子邮件
【发布时间】:2016-04-27 09:54:19
【问题描述】:

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

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

<?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);
}
?>

但这显示了以下错误。

Warning: mail() [function.mail]: "sendmail_from" not set in php.ini or custom "From:" header missing in "path"\password_generation.php on line 21

第 21 行是mail($to, $subject, $message, $headers);

【问题讨论】:

  • 检查这个:link
  • @Amine Soumiaa 它有效,但现在显示此错误Warning: mail() [function.mail]: Failed to connect to mailserver at "127.0.0.1" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in "path"password_generation.php on line 23
  • 检查 stmp 问题(第一个解决方案):link

标签: php email


【解决方案1】:

试试这个..

 <?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);
    }
    ?>

【讨论】:

  • Warning: mail() [function.mail]: Failed to connect to mailserver at "127.0.0.1" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in "path"password_generation.php on line 23 现在这个错误显示@Manjeet Barnala
  • 默认情况下,PHP 会尝试通过本地 SMTP 服务器发送,这就是为什么显示这个警告,你需要做的是编辑你的 php.ini 文件,找到 SMTP 选项并用你的smtp 服务器
  • 或者尝试将此文件上传到在线服务器并测试您的电子邮件功能,这将在线工作......
猜你喜欢
  • 2018-02-01
  • 2022-10-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-05-21
  • 2016-08-31
  • 2020-02-26
  • 1970-01-01
相关资源
最近更新 更多