簡體   English   中英

電子郵件不是通過谷歌smtp發送的

[英]Emails not sent via google smtp

我正在使用以下PHP代碼發送帶有預定義郵件附件的電子郵件。

<?php

require_once('class.phpmailer.php');

$mail             = new PHPMailer();
$body             = $_POST['message'];
$mail->IsSMTP();
$mail->SMTPAuth   = true;
$mail->Host       = "smtp.gmail.com";
$mail->Port       = 465;
$mail->Username   = "dimal.chandrasiri@gmail.com";
$mail->Password   = "****";
$mail->SMTPSecure = 'tls';
$mail->SetFrom('dimal.chandrasiri@gmail.com', 'Your name');
$mail->AddReplyTo("dimal.chandrasiri@gmail.com","Your name");
$mail->Subject    = "Abstract submission for" .$_POST['fname'];
$mail->AltBody    = $_POST['message'];

if (isset($_FILES['uploaded_file']) && $_FILES['uploaded_file']['error'] == UPLOAD_ERR_OK){
    $mail->AddAttachment($_FILES['file']['tmp_name'],$_FILES['file']['name']);
}

$mail->MsgHTML($body);
$address = 'dimal.chandrasiri@gmail.com';
$mail->AddAddress($address, $name);

if($mail->Send()) {
      echo 'done';
} else {
      echo 'error';
}

?>

密碼和其他smtp詳細信息是正確的,但我無法發送任何郵件。 我在這做錯了什么? 我使用以下html表單發布數據。

<form id="main-contact-form" class="abstract-form" name="contact-form" method="post" action="/script/submit.php">
<div class="row-fluid">
    <div class="span5">
        <label>First Name</label>
        <input type="text" name='fname' class="input-block-level" required="required" placeholder="Your First Name">
        <label>Last Name</label>
        <input type="text" name='lname' class="input-block-level" required="required" placeholder="Your Last Name">
        <label>Email Address</label>
        <input type="text" name='email' class="input-block-level" required="required" placeholder="Your email address">
        <label>File</label>
        <input type="file" name='file' class="input-block-level" required="required" placeholder="Your Abstract File">
    </div>
    <div class="span7">
        <label>Message</label>
        <textarea name="message" id="message" required="required" class="input-block-level" rows="8"></textarea>
    </div>
</div>
<button type="submit" class="btn btn-primary btn-large pull-right">Send Message</button>
<p> </p>    
</form>

當我回顯錯誤信息時,我收到以下錯誤。

The following From address failed: dimal.chandrasiri@gmail.com : Called Mail() without being connected

Gmail用戶可以在官方網站上訪問其帳戶,也可以使用第一方或第三方應用和服務。 第一方應用程序是Google的Android官方Gmail應用程序,而Thunderbird和Windows 8的郵件客戶端應用程序是第三方應用程序。

谷歌於2014年4月宣布 ,它將改善其服務的登錄安全性,並影響向公司發送用戶名和密碼的任何應用程序。

該公司建議當時切換到OAuth 2.0,但直到現在才強制執行。

如果您在Google上的安全設置下打開新的不太安全的應用頁面,您會發現Google默認禁用了訪問權限。

注意:僅當您未使用Google Apps或已為該帳戶啟用雙因素身份驗證時,才會看到該頁面。

您可以在此處翻轉開關以再次啟用安全性較低的應用程序,以便重新獲得訪問權限。

在此輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM