php mail() - 不能使用带下划线字符的电子邮件地址

时间:2014-11-13 21:56:24

标签: php email

我运行一个基本测试,用户通过html表单输入他们的详细信息,然后php脚本收集数据并通过电子邮件发送。它是一个超级基本的脚本。

现在。这个脚本有效,但我使用带下划线字符的电子邮件时例外。 example_1@yahoo.com。然后它不起作用+我也在浏览器中显示这个电子邮件地址

收件人:example_1@yahoo.com

即使我不以任何方式回应这个。 有人会知道我应该修改/添加到代码中吗?我读过preg_replace或str_replace,但不确定这是否适用于这种情况。显然,下划线是电子邮件大会的一部分,所以不确定为什么这甚至是一个问题。

我根据建议添加了一个代码:

<!DOCTYPE html>

<html>
<head>
<meta charset="UTF-8"/>
</head>

<body>
<h1>Form result : </h1> 


<?php
$first_name = $_POST['firstname'];
$second_name = $_POST['secondname'];
$email = $_POST['email'];

$to = 'example_tur@yahoo.com';
$subject = 'php test';
$message = "Hi $first_name " . "How are you $second_name .";


$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";


mail($to, $subject, $message, 'From: ' . $email,  $headers);


echo 'Welcome: ' . $first_name . '<br />';
echo 'Your last name is: ' . $second_name;
echo 'Your email is' . $email;
?>


</body>
</html>

和html按要求(请忽略css)

<html>
<head>
    <meta charset="UTF-8"/>
    <link rel="stylesheet" type="text/css" href="testphp.css" >
</head>


<body>
<form method="post" action="testphp.php">

<label for="firstname">First name: </label>
<input type ="text" name ="firstname"/>

<br>


<label for="secondname">Second name: </label>
<input type ="text" name ="secondname"/>


<br>

<label for="email">Email: </label>
<input type ="text" name ="email"/>

<br>

<input type ="submit">
</form>
</body>
</html>

0 个答案:

没有答案