简体   繁体   中英

Unsuccessful attempt to send email from gmail.com

I have file with name contact.php, inside I have form:

<form method="post" name="kontakt" action="send_mail.php">
  <fieldset class="formularz_kontaktowy">
    <legend>Formularz kontaktowy</legend>
    <div><label id="lblStatus"></label></div>
    <div><input type="text" name="txtName" title="Imię i nazwisko" id="txtName" class="text"></div>
    <div><input type="text" name="txtEmail" title="Email" id="txtEmail" class="text"></div>
    <div><input type="text" name="txtTitle" title="Tytuł" id="txtTitle" class="text"></div>
    <div><textarea cols="30" rows="10" name="txtMessage" id="txtMessage" class="text" title="Treść wiadomości"></textarea></div>
    <input type="submit" name="btnSendmail" value=Send">
  </fieldset>
</form>

send_mail.php

<?php
  require_once "Mail.php";

    $from = "<mailaddress@gmail.com>";
    $to = "<mail2@gmail.com>";
    $subject = "Hi!";
    $body = "Hi,\n\nHow are you?";

    $host = "ssl://smtp.gmail.com";
    $port = "465";
    $username = "<mailaddress@gmail.com>";
    $password = "password";

    $headers = array ('From' => $from,
      'To' => $to,
      'Subject' => $subject);
    $smtp = Mail::factory('smtp',
      array ('host' => $host,
        'port' => $port,
        'auth' => true,
        'username' => $username,
        'password' => $password));

    $mail = $smtp->send($to, $headers, $body);

    if (PEAR::isError($mail)) {
      echo("<p>" . $mail->getMessage() . "</p>");
     } else {
      echo("<p>Message successfully sent!</p>");
     }

?>  

after click btnSendmail in browser I have URL, for example: localhost/contact.php?txtName=Mary+Smith&txtEmail=mailMail%40gmail.com&txtTitle=dfd&txtMessage=fgdf&btnSendmail=Send , but mail doesn'y sent and I have not message. Why?

Try changing

$username = "<mailaddress@gmail.com>";

to

$username = "mailaddress@gmail.com";

I found problem. I had two tags , one in template and second, nested in contact.php. Thanks a lot for help.

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