Php 注册表格不向用户发送电子邮件
我有此表单,用于注册用户并发送电子邮件,以验证电子邮件是否正确,用户是否已注册,但验证电子邮件未发送到用户电子邮件 下面是PHP代码 这是HTML代码Php 注册表格不向用户发送电子邮件,php,forms,email,mysqli,Php,Forms,Email,Mysqli,我有此表单,用于注册用户并发送电子邮件,以验证电子邮件是否正确,用户是否已注册,但验证电子邮件未发送到用户电子邮件 下面是PHP代码 这是HTML代码 <form action="<?php $_SERVER['PHP_SELF']; ?>" method="post"> <table width="762" border="0" cellspacing="5" cellpadding="5"> <tr>
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
<table width="762" border="0" cellspacing="5" cellpadding="5">
<tr>
<td colspan="2" class="socialAndPeopleByName">Personal information</td>
<td colspan="2"><span class="socialAndPeopleByName">Account information</span></td>
</tr>
<tr>
<td width="91" class="registrationInfo"><span class="red">*</span> First name</td>
<td width="203"><label for="textfield"></label>
<span id="sprytextfield1">
<input name="RFname" type="text" class="registrationFeild" id="textfield"/>
<span class="textfieldRequiredMsg"><br>
First name is required.</span></span></td>
<td width="148"><span class="red">*</span><span class="registrationInfo"> User name</span></td>
<td width="255"><span id="sprytextfield5">
<input name="UserName" type="text" class="registrationFeild" id="textfield5"/>
<span class="textfieldRequiredMsg"><br>
User name is required.</span></span></td>
</tr>
<tr>
<td class="registrationInfo"><span class="red">*</span> Last name</td>
<td><span id="sprytextfield2">
<input name="RLname" type="text" class="registrationFeild" id="textfield2"/>
<span class="textfieldRequiredMsg"><br>
Last name is required.</span></span></td>
<td><span class="red">*</span><span class="registrationInfo"> Password</span></td>
<td><span id="sprypassword1">
<input name="UserPass" type="password" class="registrationFeild" id="textfield7"/>
<span class="passwordRequiredMsg"><br>
Password is required.</span><span class="passwordMaxCharsMsg"><br>
Password can't be more then 20 letter</span><span class="passwordMinCharsMsg"><br>
Password can't be less then 6 letter</span></span></td>
</tr>
<tr>
<td class="registrationInfo"><span class="red">*</span> Valid email</td>
<td><span id="sprytextfield3">
<input name="UserEmail" type="text" class="registrationFeild" id="textfield3"/>
<br>
<span class="textfieldRequiredMsg">Valid email is required.</span><span class="textfieldInvalidFormatMsg">Invalid email format.</span></span>
</td>
<td><span class="red">*</span><span class="registrationInfo"> Confirm Password</span></td>
<td><span id="sprypassword2">
<input name="UserPassConfirm" type="password" class="registrationFeild" id="textfield8"/>
<span class="passwordRequiredMsg"><br>
Please confirm your password</span></span></td>
</tr>
<tr>
<td class="registrationInfo">Web site</td>
<td><span id="sprytextfield4">
<input name="WebSite" type="text" class="registrationFeild" id="textfield4"/>
<br>
<span class="textfieldInvalidFormatMsg">Invalid format</span></span></td>
<td><span class="registrationInfo"><span class="red">*</span> Prove you are human</span></td>
<td><img src="includes/captcha.php?rand=<?php echo rand(); ?>" align="absmiddle" id='captchaimg'/> <a
href="javascript: refreshCaptcha();"><img src="images/refreshIcon.jpg" alt="Refresh" width="18"
height="25" border="0" align="absmiddle"/></a> <input
name="6_letters_code" type="text" class="registrationFeildSmall" id="6_letters_code"/></td>
</tr>
<tr>
<td colspan="3"><?php if (!empty($msg)) {
echo $msg;
} ?></td>
<td><input name="submited" type="submit" class="signUpItem" id="submited" value=""/></td>
</tr>
</table>
</form>
用户注册后会发生什么情况:
新用户已成功插入数据库。
用户收到您已成功注册的消息。
问题:以下是用户从未收到验证电子邮件的问题。更改:
$to='$USERemail';
致:
PHP不允许在单引号中插入变量的字符串。您在发送确认电子邮件时遇到问题。您需要检查它是否基本正常工作,如果不正常,请提供一些调试信息 具有一个返回值: 如果邮件已成功接受传递,则返回TRUE,否则返回FALSE 重要的是要注意,仅仅因为邮件被接受交付,并不意味着邮件将实际到达预定目的地 利用返回值编写更稳定的代码。否则你就一直坐在黑暗中 一个粗略的例子:
...
$headers = 'From:noreply@example.com' . "\r\n";
$send = mail($to, $subject, $message, $headers);
if (!$send) {
echo "Failed to send Email:\n";
var_dump($to, $subject, $message, $headers);
die();
}
然后定位实际问题。如果报告邮件已发送,但您没有看到邮件已发送,请查看您的发送邮件错误日志。我是否可以理解您为什么对我进行了降级,请在对您进行评级之前发表评论……这不起作用,请在这方面提供足够的帮助。您需要详细说明您的输入、预期和实际结果,或者具体化错误消息。否则这不被视为问题。具有返回值。检查它以尽早了解您的问题。然后实际验证在失败时所做的操作,例如var_dump$to、$subject、$message、$headers;-这只需要首先进行基本调试。找出问题所在,了解哪些参数是错误的。你最好能自己发现这些问题,这样下次遇到问题时,你就会知道更多如何处理这些问题。请为我调试我的代码对于SOthanks@tehlulz来说不是一个很合适的问题是的,这是一个问题,它现在工作得很好谢谢你的回答,我从中了解了很多。
$to = $USERemail;
...
$headers = 'From:noreply@example.com' . "\r\n";
$send = mail($to, $subject, $message, $headers);
if (!$send) {
echo "Failed to send Email:\n";
var_dump($to, $subject, $message, $headers);
die();
}