2016-09-04 4 views
1

Ich versuche, eine Website zu erstellen, die Benutzern ermöglicht, eine Liste von Kontakten per E-Mail php "mail" -Funktion. Die "Formularaktion" scheint zu aktivieren, aber wenn ich meine E-Mail überprüfe, wird es nicht angezeigt, und ich habe Spamordner überprüft. HierMeine PHP-Mail-Funktion funktioniert nicht

ist der HTML-Code:

<!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> 

Und hier ist mein PHP-Funktionscode:

<?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>"; 

    } 
} 

Bitte beachten Sie, ich habe versucht, "POST" statt "GET" verwenden und dass hat das Problem nicht behoben.

aktualisieren Ich habe eine Änderung vorgenommen PHPMailer zu verwenden, basierend auf den Vorschlägen der Kommentare: Hier ist die überarbeitete Code, aber ich bin immer noch keine E-Mail bekommen:

<?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!"; 
} 
} 

mir läuft

Windows 7, XAMPP Server und Website läuft auf localhost.

Ich denke, es ist jetzt möglich, dass der localhost immer noch auf den alten PHP-Code schaut. Hier ist der Link zu meinem Browser (localhost), wenn ich das Formular abschicke.

http://localhost/Banking%20Portal/bin/portal.php?mailto=tyler.psu.grim%40gmail.com&subject=Test&message=test&name=Tyler

+0

Welche Warnung erhalten Sie? – RiggsFolly

+0

Auf welchem ​​OS betreiben Sie das? Denken Sie daran, dass Windows nicht mit einem Mailserver ausgeliefert wird und die 'mail()' Funktion von PHP nur E-Mails an einen Mailserver weiterleitet. – RiggsFolly

+0

Ich habe das phpMailer-Tag entfernt, wie Sie es nicht sind mit 'phpMailer', aber vielleicht sollten Sie – RiggsFolly

Antwort

-1

Wenn Sie dies von localhost laufen sind, wird es nicht funktionieren. Sie können keine E-Mails von Ihrem lokalen Computer an jemanden senden. Sie können es jedoch so konfigurieren, dass E-Mails von Ihrem GMAIL/jedem anderen Konto an das angegebene Konto gesendet werden.

Lesen Sie this für weitere Klarstellung.

+0

Ja, Sie können nur einen Mail-Server ausführen oder einen SMTP-Client (wie PHPMailer) verwenden, um direkt zu senden. – Synchro

+0

Und was wird Ihre SMTP-Server-Adresse sein? 127.0.0.1 oder die temporäre IP-Adresse Ihres Computers? Wie soll der Empfänger antworten? – Kandhan

+0

Es wird eine der externen Adressen Ihres Computers sein. Wo die Antworten des Empfängers auf den MX-Eintrag Ihrer Domain gehen, hat nichts mit Outbound zu tun. – Synchro