简体   繁体   中英

php mailer error 404 wrong code

I want to make 1 simple program that can sending email to my mail so there is my program code I try to run it in domain and hosting but I got 404 error

here is the index.php not full, just some of the code

<section>
    <div class="container">
    <div class="ac">
                            <form action=’mail.php’ method=’post’>
                        <ul>
                            <li>Email   :</li><input type="text" placeholder="Your Email Address"  name='email'/>
                            <li>Name    :</li><input type="text" placeholder="Your Name" name='nama' /> 

                            <li><h1>Your Request            :<br>   <textarea placeholder="Type your request here!" style="width: 800px; height: 150px;" name='comment'  id='comment'></textarea>   <br>
                            </li></h1>


                            <button type="submit" >Submit <i class="fa fa-arrow-circle-o-right"></i></button>
                        </ul></form>

    </div>          
    </div>
</section

and this is the mail.php

        <?php
    require_once("class.phpmailer.php");
    $sendmail = new PHPMailer();

$email=$_POST[‘email’];
$nama=$_POST[’nama’];
$comment=$_POST[‘comment’];


    $sendmail->setFrom($email); //email pengirim
    $sendmail->addReplyTo($email); //email replay
    $sendmail->addAddress('venray92@gmail.com','Steven'); //email tujuan
    $sendmail->Subject = $nama; //subjek email
    $sendmail->Body=$comment ; //isi pesan
    $sendmail->isHTML(true);
    if(!$sendmail->Send())
    {
      echo "Email Sended Fail : " . $sendmail->ErrorInfo; 
    }
    else
    {
      echo "Email Sended Succesfuly!"; 
    }
?>

please help me fix it, I can't find the solution

Below is a small PHPMailer snippet that I normally use. Hope you find it useful.

function sendMail($toAddress, $subject, $body, $AttachmentFilePath) {
$mail = new PHPMailer();

$mail->IsSMTP ();
$mail->CharSet = 'UTF-8';
// nable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 0; // To prevent any outpur
// Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
// Get the hostname of the mail server
$mail->Host = 'smtp.gmail.com';
// Get the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
$mail->Port = 587;
// Get 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 = "your.email@gmail.com";
// Password to use for SMTP authentication. Specific to the Lead Qualifier Tool
$mail->Password = "YourPassWordHere";

// Set who the message is to be sent from
$mail->SetFrom ( 'your.email@gmail.com', 'Your Name' );

// To Address
$mail->AddAddress ( $toAddress, $toAddress );

$mail->Subject = $subject;

$mail->Body = $body;
$mail->AltBody = $body;

// Add attachment
if ($AttachmentFilePath != NULL)
    $mail->AddAttachment ( $AttachmentFilePath );

if (! $mail->Send ()) {
    echo "<br />Error while sending e-mail: " . $mail->ErrorInfo;
} else {
    // echo "Message sent!";
}
}

Also, since you are using Gmail, make sure you create an ASP(Application Specific Password), and use it in your code, and not your real password.

A 404 error indicates that the page wasn't found. I suspect that's due to the curly single quotes in your <form> element

<form action=’mail.php’ method=’post’>
             ^        ^        ^    ^

Change this to

<form action='mail.php' method='post'>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM