我有一个将用户添加到mysql数据库(工作)的表单,但我还需要它将新用户详细信息通过电子邮件发送到某个电子邮件地址(也可以正常工作)
问题是我无法设置2个表单操作。反正有解决这个问题吗?因此,当我单击提交时,它会将值添加到mysql表并发送电子邮件。
我的代码:
add.php:
<?php
include('database.php');
if($_POST['action'])
{
$name=$_POST['name'];
$extension=$_POST['extension'];
$department=$_POST['department'];
$phone=$_POST['phone'];
$email=$_POST['email'];
$query="INSERT INTO users (ID, Name, Email, Extension, Phone, Department) VALUES (NULL, '$name', '$email', '$extension', '$phone', '$department')";
$rez=mysql_query($query);
header("Location: index.php");
}
?>
<style type="text/css">
<!--
form { font-family: "Courier New", Courier, mono}
body { font-family: "Times New Roman", Times, serif}
-->
</style>
<form action="email.php" method="POST">
Name:<br><input type="text" name="name"><br />
Email:<br><input type="text" name="email"><br />
Extension:<br><input type="text" name="extension"><br />
Phone:<br><input type="text" name="phone"><br />
Department:<br> <select name ="department"
<option value="ADMIN">ADMIN</option>
<option value="AFTER-SALES DIRECTOR">AFTER-SALES DIRECTOR</option>
<option value="ALPINE DEALER PRINCIPAL">ALPINE DEALER PRINCIPAL</option>
<option value="AUTO ARMOUR/AUTO ENHANCE - FITMENT CENTRE (Smash and Grab)">AUTO ARMOUR/AUTO ENHANCE - FITMENT CENTRE (Smash and Grab)</option>
<option value="BANDIT-VW">BANDIT-VW</option>
<option value="BOOKINGS VW">BOOKINGS VW</option>
<option value="DRIVEWAY/WASHBAYS">DRIVEWAY/WASHBAYS</option>
<option value="FINANCE AND INSURANCE">FINANCE AND INSURANCE</option>
<option value="IT DEPARTMENT">IT DEPARTMENT</option>
<option value="MARKETING DEPARTMENT">MARKETING DEPARTMENT</option>
<option value="MASTER CARS">MASTER CARS</option>
<option value="MAYOR OF PINETOWN">MAYOR OF PINETOWN</option>
<option value="NEW CAR PREP DEPARTMENT">NEW CAR PREP DEPARMENT</option>
<option value="NUMBER PLATES">NUMBER PLATES</option>
<option value="PANELBEATER - EASIFIX - CAR CARE">PANELBEATER - EASIFIX - CAR CARE</option>
<option value="PARTS">PARTS</option>
<option value="PARTS DISPATCH">PARTS DISPATCH</option>
<option value="PARTS TELESALES">PARTS TELLESALES</option>
<option value="USED CAR PREP AND ORDERS">USED CAR PREP AND ORDERS</option>
<option value="VW NEW CARS ADMIN AND STOCK CONTROL">VW NEW CARS ADMIN AND STOCK CONTROL</option>
<option value="VW NEW VEHICLE SHOWROOM">VW NEW VEHICLE SHOWROOM</option>
<option value="VW SERVICE ADVISORS">VW SERVICE ADVISORS</option>
<option value="VW WORKSHOP">VW WORKSHOP</option>
<option value="VW WORKSHOP FOREMEN">VW WORKSHOP FOREMEN</option>
<option value="WARRANTY & CLAIMS">WARRANTY & CLAIMS</option>
<option value="WORKSHOP DRIVERS">WORKSHOP DRIVERS</option>
</select>
<br />
<br><input type="submit" name="action" value="Submit">
<input type="reset" value="Reset">
</form>
<a href="index.php">Extension List</a>
mail.php:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$extension = $_POST['extension'];
$phone = $_POST['phone'];
$department = $_POST['department'];
require 'PHPMailer-master/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "****"; // SMTP server // enables
SMTP debug information
$mail->SMTPAutoTLS = false;
$mail->SMTPSecure = false;
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Host = "****"; // sets the SMTP server
$mail->Port = 587;
$mail->Username = "****"; // SMTP account username
$mail->Password = "****"; // SMTP account password
$mail->From = "****";
$mail->FromName = "Extension List";
$mail->addAddress('****', "");
$mail->isHTML(true);
$mail->Subject = 'New Extension Added';
$mail->Body = "New User added to Extension List:" . "<br>" . "<br>" .
"Name:" . $name . "<br>" .
"Email Address:" . $email . "<br>" .
"Extension Number:" . $extension . "<br>" .
"Cell Number:" . $phone . "<br>" .
"Department:" . $department;
if(!$mail->Send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
echo 'Email Sent Successfully!';
?>
答案 0 :(得分:0)
示例:
$pdo = new PDO('mysql:host='.DATABASE_HOST.';dbname='.DATABASE_NAME, DATABASE_USERNAME, DATABASE_PASSWORD);
$stm = $pdo->prepare("insert into `phone` (`name`, `number`) values (:name, :number)");
$stm->bindParam(':name', $name);
$stm->bindParam(':number', $number);
$stm->execute();
header()
调用之上。然后你就可以摆脱重复的变量初始化。答案 1 :(得分:0)
首先,要小心这个毫无准备的SQL查询!它容易受到SQL注入攻击,我建议你改用预备语句。
关于您的主要问题,您可以:
在#Login to your sub
login-azurermaccount
Select-AzureRmSubscription -SubscriptionName 'BizSpark'
$vms = Get-AzureRmVM
#list all the VMs returned by the above command
$vms
#first VM in the above collection
$vms[0]
#id of first vm
$vms[0].id
条件之后立即在add.php中添加include('mail.php')
。如果表格执行,这将执行mail.php的内容,发送电子邮件,
或
通过Ajax和javascript发送一个表单,然后让另一个表格正常发送