[英]Mail Not send to the user
Hi Im creating a form in which i enter the user details and provide them user name and password through email for login purpose. 嗨,我创建了一个表单,我在其中输入用户详细信息,并通过电子邮件为他们提供用户名和密码以用于登录。
Problem: Using post method i would like to send email to the user. 问题:我想使用发布方法向用户发送电子邮件。 But it shows the email sent but email not yet received.
但它显示已发送但尚未收到的电子邮件。
If to address is directly given email is sent. 如果直接给出地址,则发送电子邮件。 $to:email@domain.com - mail is sent.
$ to:email@domain.com-发送邮件。
Im sending email in localhost using Send mail. 我使用发送邮件在本地主机中发送电子邮件。
My form is 我的表格是
<form name="assignteacher" method="post" action="../path.php">
<table align="center" width="450px">
<tr>
<td valign="top">
<label for="teacherid">Teacher ID</label>
</td>
<td valign="top">
<input type="text" name="teacherid" maxlength="50" size="30">
</td>
</tr>
<tr>
<td valign="top">
<label for="email">Email</label>
</td>
<td valign="top">
<input type="email" name="email" maxlength="50" size="30">
</td>
</tr>
<tr>
<td valign="top">
<label for="username">User Name</label>
</td>
<td valign="top">
<input type="text" name="username" maxlength="50" size="30">
</td>
</tr>
<tr>
<td valign="top"">
<label for="password">Password</label>
</td>
<td valign="top">
<input type="text" name="password" maxlength="50" size="30">
</td>
</tr>
<tr>
<td valign="top">
<label for="class">Class Assigned</label>
</td>
<td valign="top">
<input type="text" name="class" maxlength="80" size="30">
</td>
</tr>
<tr>
<td colspan="2" style="text-align:center">
<input type="submit" value="Submit">
<a href="http://www.freecontactform.com/email_form.php">Email Form</a>
</td>
</tr>
</table>
</form>
My PHP Code is.. 我的PHP代码是..
<?php
$emailid=$_POST['email'];
$to='$emailid';
$subject='Your Login info';
$message ="username: ".$_POST['username']."\r\n";
$message .= "Password: ".$_POST["password"]."\r\n";
$message .= "class: ".$_POST["class"]."\r\n";
$headers="from:myemail@gmail.com" . "\r\n" .
"Reply_to:myemail@gmail.com" . "/r/n" .
"MIME-version:1.0" . "\r\n" .
"Content-type:text/html" . "\r\n" .
"X-Mailer:PHP/" . phpversion();
if(mail($to, $subject, $message, $headers))
echo "mail sent";
else
echo"mail sending failed";
?>
Kindly help me in this. 请帮助我。 bear with me if i made any spell or grammar mistakes.
如果我犯了任何拼写或语法错误,请和我一起忍受。
No need for giving single quotes to $to='$emailid';
无需给
$to='$emailid';
单引号$to='$emailid';
as it is a PHP varible containing string value. 因为它是一个包含字符串值的PHP变量。 Give as below:
给出如下:
$to=$emailid;
If you are using Xampp, you have to modify 2 ini files: php.ini and sendmail.ini 1)look for mail function in php.ini(c:/xampp/php/php.ini)>>[mail function] change the following: 如果您使用的是Xampp,则必须修改2个ini文件:php.ini和sendmail.ini 1)在php.ini中查找邮件功能(c:/xampp/php/php.ini)>> [邮件功能]更改下列:
SMTP=smtp.gmail.com
smtp_port=587
sendmail_from = from@gmail.com
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
2) next modify sendmail.ini(c:/xampp/sendmail/sendmail.ini) Edit the following lines (or copy and paste if you don't have them then edit it) 2)接下来修改sendmail.ini(c:/xampp/sendmail/sendmail.ini)编辑以下几行(如果没有它们,请复制并粘贴然后编辑)
account Gmail
tls on
tls_certcheck off
host smtp.gmail.com
from x@gmail.com
auth on
user x@gmail.com
password x
port 587
account default : Gmail
Save both of these files then test it with this code 保存这两个文件,然后使用此代码进行测试
<?php
$subject="Test mail";
$to="someone@whatever.com";
$body="This is a test mail";
if (mail($to,$subject,$body)) {
echo "Mail sent successfully!";
} else {
echo"Mail not sent!";
}
?>
The second line $to='$emailid';
第二行
$to='$emailid';
should be $to=$emailid;
应该是
$to=$emailid;
It's worth pointing out that this is a massive security risk - this code shouldn't be available on the public Internet, unless it's password protected. 值得指出的是,这是一个巨大的安全风险-除非受密码保护,否则该代码不应在公共Internet上可用。
You are using HTML 5 attribute for input, It will work only on modern browsers.. So do changes as follows 您正在使用HTML 5属性进行输入,它将仅在现代浏览器上工作。
in HTML 在HTML中
<input type="text" name="email" maxlength="50" size="30">
in PHP fix error 在PHP中修复错误
$to=$emailid;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.