任何人都可以帮我解决这个问题。试图发生什么即时通讯是当我提交一个PHP表单到我的MySQL数据库,一个电子邮件同时发送,但我想要发生的是,该电子邮件发送到表单上输入的电子邮件地址。可悲的是什么,我都尝试过没有在这里工作是我到目前为止有:
这里是形式:
<form action="index.php" method="post" id="add_player_form" name="form">
<input type="hidden" name="action" value="add_player"/>
<h3>Add New Player</h3>
<label>First Name:</label>
<input type="text" name="first_name" />
<br /><br />
<label>Last Name:</label>
<input type="text" name="last_name" />
<br /><br />
<label>Email:</label>
<input type="text" name="email" />
<br /><br />
<label>Position:</label>
<input type="text" name="position" />
<br /><br />
<label>Date Of Birth:</label>
<input type="text" name="dob" />
<br /><br />
<label>Country:</label>
<input type="text" name="country" />
<br /><br />
<label>City/Town:</label>
<input type="text" name="city_town" />
<br /><br />
<label></label><input type="submit" value="ADD" onClick="randomString();" />
<br /><br />
<input type="hidden" name="user_type_id" value="2" />
<input type="hidden" name="team_id" value="<?php echo $teamId ?>" />
<input type="hidden" name="password" value=""/>
</form>
这里是index.php的PHP代码:
else if ($action == 'add_player') {
$last_name = $_POST['last_name'];
$first_name = $_POST['first_name'];
$dob = $_POST['dob'];
$position = $_POST['position'];
$email = $_POST['email'];
$country = $_POST['country'];
$city_town = $_POST['city_town'];
$password = $_POST['password'];
$team_id = $_POST['team_id'];
$user_type_id = $_POST['user_type_id'];
add_player($last_name, $first_name, $dob, $position, $email, $country, $city_town, $password, $team_id, $user_type_id); //edit
$team_manager = get_players();
//$to = $_POST['email']; // this is the player's Email address
$from = "[email protected]"; // this is the web app's Email address
$subject = "Welcome to Team Manager";
$message = "You have been added to a team on our web app TEAM MANAGER!" . "\n\n" . "In order to login to your team please use
the following details: " . "\n\n" . "Email: " . $email . "\n\n" . "Password: " . $password;
//$message = $first_name . " " . $last_name . " wrote the following:" . "\n\n" . $_POST['message'];
$headers = "From:" . $from;
mail($email, $subject, $message, $headers);
include('userPage.php');
}
也是我的SMTP配置:
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = smtp.live.com
; http://php.net/smtp-port
smtp_port = 25
; For Win32 only.
; http://php.net/sendmail-from
sendmail_from = [email protected]
任何帮助将非常感激,如果你需要更多的信息请求问问,欢呼每一个人!
你的代码应该工作。你的问题到底是什么?你是否收到了一些错误,或者它是否发送到$ _POST ['email']以外的地方? – Rob
在你的代码中:首先注意到的是,片断丢失。就像代码从else开始,如果..和include在底部。那些应该被删除,因为它们与问题无关,或者它们是?第二件事是,我看不到任何对mysql的引用,或者是'add_player();'mysql函数? –
您的某个功能有问题。没有他们测试了这一点,电子邮件进入,并从输入。 –