任何人都可以帮我解决这个问题。我试图发生的是当我向我的MySQL数据库提交一个php表单时,同时发送一封电子邮件,但我想要发生的是将该电子邮件发送到表单上输入的电子邮件地址。遗憾的是,我所尝试过的任何东西都不能在这里工作到目前为止:
以下是表格:
<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 = "teammanager0@outlook.com"; // 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 = teammanager0@outlook.com
任何帮助都将非常感激,如果您需要更多信息,请询问,欢呼大家!
答案 0 :(得分:1)
所以,没有人回答,可能我会得到一些downvotes。但是你的问题不会自行消失,所以让我们开始调试!
我注意到的第一件事是,代码是不完整的,所以基本上没有它,我们无法确认,问题不在其他地方。既然你说它不相关,我删除了所有内容,注释掉了/和/或我们没有任何引用(比如mysql函数等)。
由于缺少某些代码,我不知道您的问题是否存在。但是else if ($action == 'add_player') {
在开始时<input type="hidden" name="action" value="add_player"/>
会提示您错过了_POST操作值。如果是这种情况,请在代码的头部添加$action = $_POST['action'];
。或者将$action
更改为$_POST['action']
。
如果上述想法无效,请尝试我的汉密码:
<?
// Removed the first hidden input and merged it with submit button
if ($_POST['action'] == 'Add Player') {
print 'Submit action was trigged, lets hope also the mails report is going to be good.<br />';
$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'];
$from = "TeamManager <teammanager0@outlook.com>"; // Made format different, to support the name
$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;
$headers = "From: " . $from; // added whitespace
if (mail($email, $subject, $message, $headers)) {
print 'Email was sent by the PHP code, and the rest is up to the gods of the internet highway.<br />';
}
}
print '<form action="" method="post">
<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" name="action" value="Add Player" onClick="randomString();" />
<br />
<br />
<input type="hidden" name="user_type_id" value="2" />
<input type="hidden" name="team_id" value="" />
<input type="hidden" name="password" value=""/>
</form>';
您可以看到此代码已经过相当调试,隐藏的输入也已替换为submit-trigger。试试看,让我们知道结果是什么,你看到了两个注意事项吗?
编辑:所以,上面的代码在我的服务器上工作正常。这意味着,如果我从你的代码中弄出来的东西不是问题(我们无法在没有看到它的情况下验证它),那么你的代码就不是问题了。可能的其他问题是:
答案 1 :(得分:0)
我弄清楚问题是什么,我没有为我的smpt设置配置正确的php文件,感谢大家回答我的问题,非常感谢!