您好我使用PHPMailer创建联系表单。但我无法解决这部分代码。
$content = '<div style="background: #eee; padding: 10px; font-size: 14px">'.$message.'</div>';
$mail->MsgHTML($content);
使用$ message代码,我只能收到邮件用户的邮件。但我也想了解他/她的姓名,年龄,电子邮件等。我将这些定义为$ name $ email $ age等。但我不能在内容中添加它。我怎样才能做到这一点?对不起我的英语不好。 感谢
我的所有文件都在这里:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
<title>PHPMailer ile E-posta Gönderimi (DEMO) - Erbilen.NET</title>
<style type="text/css">
* {
padding: 0; margin: 0; list-style: none; border: none; font-family: Arial; font-size: 14px
}
textarea, input {
border: 1px solid #ddd;
border-top-color: #aaa;
border-left-color: #aaa;
padding: 7px;
resize: none
}
input:focus, textarea:focus {
outline: 1px solid #205ec1
}
button {
background: #205ec1;
color: #fff;
padding: 7px 13px;
cursor: pointer
}
form {
width: 400px;
margin: 20px auto;
background: #f9f9f9;
padding: 10px;
border: 1px solid #ddd;
border-top-color: #aaa;
border-left-color: #aaa
}
form h3 {
font-size: 21px;
font-weight: normal;
margin-bottom: 10px;
border-bottom: 1px solid #ddd;
padding-bottom: 10px
}
table tr td {
padding: 6px;
}
.success {
border: 1px solid green;
color: green;
padding: 10px;
margin: 20px auto;
width: 400px
}
.error {
border: 1px solid red;
color: red;
padding: 10px;
margin: 20px auto;
width: 400px
}
</style>
</head>
<body>
<?php
if ( $_POST ){
$adsoyad = htmlspecialchars(trim($_POST['adsoyad']));
$fakulte = htmlspecialchars(trim($_POST['fakulte']));
$iletisim = htmlspecialchars(trim($_POST['iletisim']));
$eposta = htmlspecialchars(trim($_POST['eposta']));
$istel = htmlspecialchars(trim($_POST['istel']));
$ceptel = htmlspecialchars(trim($_POST['ceptel']));
$iletisim = htmlspecialchars(trim($_POST['iletisim']));
$liste = htmlspecialchars(trim($_POST['liste']));
$digeryayin = htmlspecialchars(trim($_POST['digeryayin']));
$yayinadi = htmlspecialchars(trim($_POST['yayinadi']));
$yazaradi = htmlspecialchars(trim($_POST['yazaradi']));
$yayinevi = htmlspecialchars(trim($_POST['yayinevi']));
$isbn = htmlspecialchars(trim($_POST['isbn']));
$gorulme = htmlspecialchars(trim($_POST['gorulme']));
include 'class.phpmailer.php';
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port
$mail->Username = '-----r@gmail.com';
$mail->Password = '-----';
$mail->From = $_POST["eposta"];
$mail->FromName = $_POST["adsoyad"];
$mail->AddAddress('----@gmail.com'); // Name is optional
$mail->CharSet = 'UTF-8';
$mail->Subject = 'Konu';
$mail->IsHTML(true);
$content = '
<img height="40" width="230" src="varsa logo linki" /><br />
<table>
<tr>
<td>Kullanıcı Adınız:</td>
<td>'.$adsoyad.'</td>
</tr>
<tr>
<td>Güvenlik Kodunuz:</td>
<td>'.$fakulte.'</td>
</tr>
<tr>
<td>İsim Soyisim:</td>
<td>'.$iletisim.'</td>
</tr>
<tr>
<td>Email Adresiniz:</td>
<td>'.$eposta.'</td>
</tr>
</table>';
$mail->MsgHTML($content);
if($mail->Send()) {
// e-posta başarılı ile gönderildi
echo '<div class="success">E-posta başarıyla gönderildi, lütfen kontrol edin.</div>';
} else {
// bir sorun var, sorunu ekrana bastıralım
echo '<div class="error">'.$mail->ErrorInfo.'</div>';
}
}
?>
<form action="" method="post">
<h3>Kullanıcı Bilgileri</h3>
<table>
<tr>
<td width="108">Adınız Soyadınız</td>
<td width="280"><input type="text" name="adsoyad" style="width: 250px; height: 25px" /></td>
</tr>
<tr>
<td>Fakülteniz</td>
<td><input name="fakulte" type="text" style="width: 250px; height: 25px" /></td>
</tr>
<tr>
<td>İletişim Bilgileriniz</td>
<td><textarea name="iletisim" cols="42" rows="4"></textarea></td>
</tr>
<tr>
<td>E-Mail</td>
<td><input type="email" name="eposta" style="width: 250px; height: 25px" /></td>
</tr>
<tr>
<td>İş Telefonu</td>
<td><input type="text" name="istel" style="width: 250px; height: 25px" /></td>
</tr>
<tr>
<td>Cep Telefonu</td>
<td><input type="text" name="ceptel" style="width: 250px; height: 25px" /></td>
</tr>
</table>
</form>
<form action="" method="post">
<h3>Yayın Bilgileri</h3>
<table>
<tr>
<td width="108">Yayın Türü</td>
<td width="280"><select name="liste">
<option value="kitap">Kitap</option>
<option value="dergi">Dergi</option>
<option value="seskasedi">Ses Kasedi</option>
<option value="videokasedi">Video Kasedi</option>
<option value="vcd">VCD</option>
<option value="dvd">DVD</option>
<option value="cd">CD</option>
<option value="disket">Disket</option>
</select>
<input type="text" name="digeryayin" value="Diğer (Belirtiniz)" style="width: 250px; height: 25px; margin-top: 5px" />
</td>
</tr>
<tr>
<td>Yayın Adı</td>
<td><input type="text" name="yayinadi" style="width: 250px; height: 25px" /></td>
</tr>
<tr>
<td>Yazar Adı & Soyadı</td>
<td><input type="text" name="yazaradi" style="width: 250px; height: 25px" /></td>
</tr>
<tr>
<td>Yayınevi</td>
<td><input type="text" name="yayinevi" style="width: 250px; height: 25px" /></td>
</tr>
<tr>
<td>ISBN-ISSN</td>
<td><input type="text" name="isbn" style="width: 250px; height: 25px" /></td>
</tr>
<tr>
<td>Yayını Nerede Gördünüz?</td>
<td><textarea name="gorulme" cols="42" rows="4"></textarea></td>
</tr>
<tr>
<td></td>
<td><button type="submit">Gönder</button></td>
</tr>
</table>
</form>
</body>
</html>
答案 0 :(得分:0)
您应该使用:
$mail->Body = $content;
将HTML内容提供给PHPMailer。
答案 1 :(得分:0)
这不是一个电子邮件问题,它只是简单的PHP语法。在多个内容字符串中嵌入多个变量的最简单方法是在heredoc中使用字符串插值,如下所示:
$content = <<<EOT
<div style="background: #eee; padding: 10px; font-size: 14px">$name</div>
<div style="background: #eee; padding: 10px; font-size: 14px">$email</div>
<div style="background: #eee; padding: 10px; font-size: 14px">$age</div>
<div style="background: #eee; padding: 10px; font-size: 14px">$message</div>
EOT;
使用heredoc意味着您不必担心变量中的嵌入式引号。