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服务器更改它,或者尝试将此文件上载到联机服务器并测试电子邮件功能,这将联机工作。。。