我无法通过php发送电子邮件。我甚至尝试使用PHPmailer
也没有用。我尝试了一切。 php mail()。邮寄地址。我需要添加联系表单上的按钮提交按钮,以便将新用户详细信息通过电子邮件发送给我的老板,因为它将其添加到数据库中。它增加了用户的罚款,但我无法收到要发送的电子邮件。我正在使用linux debian pc。
真的很感激任何帮助
这是我的代码:
<?php
session_start();
if(!isset($_SESSION['SESS_MEMBER_ID'])){
header("Location:login.php");
}
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="formvalid.css">
<script src="formvalid.js"></script>
<style type="text/css">
td{border-right:1px solid #cccccc;padding:2px;text-align:center;}
table.gridtable {
font-family: verdana,arial,sans-serif;
font-size:18px;
color: #000000;
border-width: 1px;
border-color: #666666;
border-collapse: collapse;
}
table.gridtable th {
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #666666;
background-color: #dedede;
}
table.gridtable td {
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #666666;
background-color: #ffffff;
}
</style>
<title><?php if(!$title){?>Alpine VW Extension List<?php }else{ echo $title; }//end if?></title>
</head>
<body>
<?php
mysql_connect("localhost", "root", "^h1dDeN!") or die(mysql_error());
mysql_select_db("phonebook") or die(mysql_error());
$mode = $_GET['mode'];
$checkSql="select count(id) as eCount from address where ext = " . $_POST['ext'];
$result = mysql_query($checkSql);
$row = mysql_fetch_assoc($result);
if($row['eCount'] > 0) {
echo "Extension Number already exists";
$mode = 'add';
}
if($row['eCount'] == 999){
$disable = 1;
}
switch($mode){
case 'add':
?>
<h2>Add Contact</h2>
<form name="form1" action="<?=$_SERVER['PHP_SELF'];?>?mode=added" method="post">
<div align="center"><table class="searchable">
<tr><td>Extension:</td><td><div align="center">
<input type="text" name="ext" required />
<span class="error">* <?php echo $nameErr;?></span>
</div></td></tr>
<tr><td>Name:</td><td><div align="center">
<input type="text" name="name" required />
<span class="error">* <?php echo $nameErr;?></span>
</div></td></tr>
<tr><td>Department:</td><td><div align="center"><select name="department" required>
<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>
<span class="error">* <?php echo $nameErr;?></span>
</div></td></tr>
<tr><td>Email:</td><td><div align="center">
<input type="text" name="email" pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,3}$" name="email" title="Example: user@company.co.za" required/>
<span class="error">* <?php echo $nameErr;?></span>
</div></td></tr>
<tr><td>Cellphone:</td><td><div align="center">
<input type="text" name="phone" />
</div></td></tr>
<tr><td colspan="2" align="center"><a href="javascript:history.go(-1);">Back</a> | <input type="submit" name="submit" id="submit" value="Add New Contact"<?php if($disable ==1){?>disabled<?php } ?>/></td></tr>
<input type="hidden" name="mode" value="added">
</table>
</div>
</form>
<?php
break;
case 'added':
$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$department = $_POST['department'];
$ext = $_POST ['ext'];
$sql = "INSERT INTO address (ext, name, department ,email, phone) VALUES ('" . $ext . "','" . $name . "','" . $department . "', '" . $email . "', '" . $phone . "')";
mysql_query($sql);
header('location: ' . $_SERVER['PHP_SELF']);
break;
case 'edit':
?>
<h2>Editing: <?php echo $_GET["id"]; ?></h2>
<form name="form1" action="<?=$_SERVER['PHP_SELF'];?>?mode=edited" method="post">
<table width="399" class="searchable">
<tr><td width="87">Extension Number:</td>
<td width="551"><div align="center">
<input type="text" value="<?=$_GET['ext']?>" name="ext" />
</div></td></tr>
<tr><td>Name:</td><td><div align="center">
<input type="text" value="<?=$_GET['name'];?>" name="name" />
</div></td></tr>
<tr><td>Email:</td><td><div align="center">
<input type="text" value="<?=$_GET['email'];?>" name="email" />
</div></td></tr>
<tr><td>Cellphone:</td><td><div align="center">
<input type="text" value="<?=$_GET['phone'];?>" name="phone" />
</div></td></tr>
<tr><td colspan="2" align="center"><a href="javascript:history.go(-1);">Back</a> |<input name="Submit" type="submit" value="Save Changes" /></td></tr>
<input type="hidden" name="mode" value="edited">
<input type="hidden" name="id" value="<?=$_GET['id'];?>">
</table>
</form>
<?php
break;
case 'edited':
$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$Ext = $_POST ['Ext'];
$id = $_POST['id'];
$sql = "UPDATE address SET name = '" . $name ."', phone = '" . $phone . "', email = '" . $email . "', Ext = '" . $Ext . "' WHERE id = '" . $id . "'";
mysql_query($sql);
header('location: ' . $_SERVER['PHP_SELF']);
break;
case 'remove':
$id = $_GET['id'];
$sql ="delete from address where id= '" . $id ."'";
mysql_query($sql);
header('location: ' . $_SERVER['PHP_SELF']);
break;
default:
$depts = [];
$res = mysql_query("SELECT * FROM address ORDER BY department, name");
while ($row = mysql_fetch_assoc($res)) {
if (!isset($depts[$row['department']])) {
$depts[$row['department']] = [];
}
$depts[$row['department']][] = $row;
}
?>
<div align="center"><h1>Alpine VW Extension List</h1></div>
<div align="center"><table class="gridtable">
<tr>
<th width="100">Extension</th>
<th width="100">Name</th>
<th width="200">Email</th>
<th width="200">Cellphone</th>
<th width="200" colspan="2">Admin</th>
</tr>
<tr>
<td colspan="6">
<?php if ($disable != 1) : ?>
<b><a href="<?= $_SERVER['PHP_SELF'] ?>?mode=add">Add Contact</b </a>
<?php else : ?>
<span>Contact Book is Full</span>
<?php endif ?>
</td>
</tr>
<?php foreach ($depts as $dname => $contacts) : ?>
<tr>
<td colspan="6"><?= $dname ?></td>
</tr>
<?php foreach ($contacts as $contact) : ?>
<tr>
<td><?= $contact['Ext'] ?></td>
<td><?= $contact['name'] ?></td>
<td><a href="mailto:"<?= $contact['email'] ?>"><?= $contact['email'] ?></a></td>
<td><?= $contact['phone'] ?></td>
<td><a href="<?= $_SERVER['PHP_SELF'] ?>?id=<?= $contact['id'] ?>&mode=edit" >Edit </a></td>
<td><a href="<?= $_SERVER['PHP_SELF'] ?>?id=<?= $contact['id'] ?>&mode=remove">Remove</a></td>
</tr>
<?php endforeach ?>
<?php endforeach ?>
</div>
</table>
<?php
break;
}
?>
</body>
</html>
<?php ob_flush();?>
答案 0 :(得分:1)
根据您的问题,不使用任何mail()函数 但如果你想要php邮件功能,那么这里是代码。您必须根据需要更改变量和标签
if(isset($_POST["submit"]))
{
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$name = $_POST['email'];
$email = $_POST['address'];
$addressa = $_POST['name'];
$addressb = $_POST['phone'];
$phone = $_POST['number'];
$mes = $_POST['type'];
$how = $_POST['date'];
$headers .= 'Cc: '.$name."\r\n";
$to = '********@gmail.com';
$subject = 'subject';
$message = "Email : ".$name."\r\n <br>".
"Address : ".$email."\r\n <br>".
"Name : ".$addressa."\r\n <br>".
"Phone : ".$addressb."\r\n <br>".
"Number Of Seats : ".$phone."\r\n <br>".
"Date : ".$how."\r\n <br>".
"Type : ".$mes."\r\n <br>";
$result = mail($to, $subject, $message,$headers);
if(!$result) {
echo "<script>alert('Not Send Successfully');document.location='page.php'</script>";
} else {
echo "<script>alert('Send Successfully');document.location='page.php'</script>";
}
}
答案 1 :(得分:0)
哦,拜托,请不要将您的数据库密码发送给我们......
请注意,根据PhP documentation,PhP mail()
功能适用于某些服务器配置。
然而,PhPMailer使用其own protocol implementation,因此您可以进行一些更改以在方法之间切换。你能把错误发给我们吗?