php "mail"기능을 통해 연락처 목록을 이메일로 보낼 수있는 웹 사이트를 만들려고합니다. "form action"하지만 내 메일을 확인해도 표시되지 않으며 스팸 폴더를 확인합니다. 여기 내 PHP 메일 기능이 작동하지 않습니다.
는 HTML 코드입니다 :<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Case</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h2>TTP Banking Portal</h2>
<ul class="nav nav-tabs">
<li class="active"><a data-toggle="tab" href="#home">Home</a></li>
<li><a data-toggle="tab" href="#withdraw">Withdraw</a></li>
<li><a data-toggle="tab" href="#menu2">Menu 2</a></li>
<li><a data-toggle="tab" href="#menu3">Menu 3</a></li>
<li><a data-toggle="tab" href="#email">Email</a></li>
</ul>
<div class="tab-content">
<div id="home" class="tab-pane fade in active">
<h3>My Account</h3>
<p>Welcome back, Tyler B. Grim</p>
<h2>Account Details:</h2>
<h3>
<h2>Do you want to:</h2>
<a data-toggle = "tab" href = "#withdraw">Withdraw</a>
</div>
<div id="withdraw" class="tab-pane fade">
<h3>Menu 1</h3>
<p>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
</div>
<div id="menu2" class="tab-pane fade">
<h3>Menu 2</h3>
<p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam.</p>
</div>
<div id="menu3" class="tab-pane fade">
<h3>Menu 3</h3>
<p>Eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo.</p>
</div>
<div id="email" class="tab-pane fade">
<form action = "../bin/portal.php?func_name=sendMail" method = "get">
<p>Send Mail to:</p>
<input type = "radio" name = "mailto" value = "[email protected]">[email protected]<br/>
<input type = "radio" name = "mailto" value = "[email protected]">[email protected]<br/>
<input type = "radio" name = "mailto" value = "[email protected]">[email protected]<br/>
<p>Subject:</p>
<input type = "text" name = "subject" placeholder = "Enter email subject:" />
<p>Message Body</p>
<input type = "text" name = "message" placeholder = "Enter email body here:" style="height:250px;width:1000px">
<p>Signature</p>
<input type = "text" name = "name" placeholder = "Enter name here"/>
<br/>
<br/>
<input type = "submit">Send Mail</input>
</div>
</div>
</body>
</html>
그리고 여기 내 PHP 함수 코드입니다 :
<?php
function sendMail() {
if (isset($_GET["mailto"])) {
$to = $_GET["mailto"];
}
else {
echo "<script type = 'text/javascript'>alert('No message recipient selected')</script>";
}
$message = $_GET["message"];
$subject = $_GET["subject"];
$name = $_GET["name"];
if ($to) {
$sendTo = $to;
$sendSubject = $name . " " . $subject;
$sendMessage = $message;
if (mail($sendTo, $sendSubject, $sendMessage)) {
echo "<script type = 'text/javascript'>alert('Message Sent')</script>";
}
else {
echo "<script type = 'text/javascript'>alert('Your Computer Doesn't support PHP Mail Functionality.')</script>";
}
}
else {
echo "<script type = 'text/javascript'>alert('You need to enter a recipient before you can send an email')</script>";
}
}
내가 대신 "GET"의 "POST"를 사용하여 시도하고 있다는 것, 유의하시기 바랍니다 문제를 해결하지 못했습니다.
<?php
function sendMail() {
date_default_timezone_set('Etc/UTC');
require '..//bin//PHPMaster-mailer//PHPMailerAutoload.php';
//Create a new PHPMailer instance
$mail = new PHPMailer;
//Tell PHPMailer to use SMTP
$mail->isSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 2;
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = 'smtp.gmail.com';
// use
// $mail->Host = gethostbyname('smtp.gmail.com');
// if your network does not support SMTP over IPv6
//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
$mail->Port = 587;
//Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPSecure = 'tls';
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication - use full email address for gmail
$mail->Username = "****************";
//Password to use for SMTP authentication
$mail->Password = "****************";
//Set who the message is to be sent from
$mail->setFrom($_GET["email"], $_GET["name"]);
//Set an alternative reply-to address
$mail->addReplyTo($_GET["email"], $_GET["name"]);
//Set who the message is to be sent to
$mail->addAddress($_GET["to"], $_GET["to"]);
//Set the subject line
$mail->Subject = $_GET["subject"];
$mail->AltBody = $_GET["message"];
//Attach an image file
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
}
내가 실행하고 : 그러나 나는 아직도 이메일을받지 못했습니다, 다음은 수정 된 코드는 다음과 같습니다
업데이트 나는 의견의 제안에 따라 PHPMailer를 사용하도록 변경 한
Windows 7, XAMPP Server 및 웹 사이트가 localhost에서 실행 중입니다.
localhost가 여전히 오래된 PHP 코드를보고있는 것이 가능하다고 생각합니다. 양식을 제출할 때 내 브라우저 (로컬 호스트)에 제출 된 링크는 다음과 같습니다.
경고는 무엇입니까? – RiggsFolly
이 OS를 실행하고있는 OS는 Windows가 메일 서버에 오지 않는다는 것을 기억하고 PHP의'mail()'함수는 실제로 메일 자체에 메일을 보내지 않는 메일 서버에만 메일을 전달합니다. – RiggsFolly
phpMailer 태그를 제거했습니다. 'phpMailer'를 사용하지만 어쩌면 당신은 – RiggsFolly