2016-08-17 4 views
2

私はsmtpなしでphpメールを送っています。メールサーバはsmtpを使わないでメールを送ることを許可していません。私は多くのオプションを試しましたが、修正できません。私はPHPの世界では新しいです。私はそれを修正するのを助けてください。 これは私のPHPのメールコードです:smtpでphpメールを設定する

<?php 

/** 
* Sends an e-mail based on a template 
* 
* @param $template_name 
* @param $template_data 
* @param $recipient_mail 
* @param $subject 
* @param bool $is_admin 
* @throws Exception 
* @throws SmartyException 
*/ 
function send_email_template($template_name, $template_data, $recipient_mail, $subject, $is_admin = false){ 

    global $template; 

    $template->assign('mail', $template_data); 

    if($is_admin) { 
     $body = $template->fetch(ADMIN_TEMPLATE . 'email/' . $template_name); 
    }else{ 
     $body = $template->fetch(CURRENT_TEMPLATE . 'email/' . $template_name); 
    } 

    $headers = sprintf('From: %s', get_setting('email_from')) . '\r\n'; 
    $headers .= 'MIME-Version: 1.0' . "\r\n"; 
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 

    mail($recipient_mail, $subject, $body, $headers); 

} 

/** 
* Checks if email exists based on given $email 
* 
* @param $email 
* @return bool 
*/ 
function email_exists($email){ 

    $sql = 'select * from members where members_email = ' . make_safe($email); 
    return fetch_row($sql); 

} 

/** 
* Updates the email code for a member based on their email 
* 
* @param $email 
* @param $email_code 
* @return bool 
*/ 
function update_email_code($email, $email_code){ 

    global $database; 

    try { 

     $rs = $database->Execute('select * from members where members_email = ' . make_safe($email)); 

     $member = array(); 

     $member['members_email_code'] = $email_code; 

     $updateSQL = $database->GetUpdateSQL($rs, $member); 
     $database->Execute($updateSQL); 

     return true; 

    } catch (exception $e) { 

     error_log($e); 

     return false; 

    } 

} 
+0

あなたは[PHPMailer](https://github.com/PHPMailer/PHPMailer)でこれをタグ付けしました。なぜそれを使用しないのですか?それは非常に簡単に認証でSMTPを行うことができます。 – Synchro

答えて

2

はSMTPを使ってメールを送信するには、このスクリプトを使用してください。 この場合、Google SMTPサーバーを使用しています。このリンクを使用して、Google SMTP https://support.google.com/a/answer/176600?hl=enについて知ることができます。 >https://myaccount.google.com/security?utm_source=OGB&pli=1#connectedapps

クリック「以下が可能に - あなたは、あなたのSMTPアカウントの設定に

行くようにGmailのを使用している場合は、コードの下

<?php 
    ini_set("SMTP", "aspmx.l.google.com"); 
    ini_set("sendmail_from", "[email protected]"); 

    $message = "The mail message was sent with the following mail setting:\r\nSMTP = aspmx.l.google.com\r\nsmtp_port = 25\r\nsendmail_from = [email protected]"; 

    $headers = "From: [email protected]"; 


    mail("[email protected]", "Testing", $message, $headers); 
    echo "Check your email now....<BR/>"; 
?> 
+0

私はこのスクリプトを試してみましたが動作していません – Xhulo

+0

Google SMTPを使用している場合は、Gmailアカウントで有効にする必要があります。このリンクを使用して、SMTPを使用してメールを送信する方法を確認してください。http://stackoverflow.com/questions/712392/send-email-using-the-gmail-smtp-server-from-a-php-page – kikuyu1

+0

もちろん、もちろんですがもう一度 – Xhulo

0

は私

require_once('../class.phpmailer.php'); 

//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded 

$mail    = new PHPMailer(); 

$body    = file_get_contents('contents.html'); 
$body    = eregi_replace("[\]",'',$body); 

$mail->IsSMTP(); // telling the class to use SMTP 
$mail->Host  = "mail.yourdomain.com"; // SMTP server 
$mail->SMTPDebug = 2;      // enables SMTP debug information (for testing) 
              // 1 = errors and messages 
              // 2 = messages only 
$mail->SMTPAuth = true;     // enable SMTP authentication 
$mail->Host  = "mail.yourdomain.com"; // sets the SMTP server 
$mail->Port  = 26;     // set the SMTP port for the GMAIL server 
$mail->Username = "[email protected]"; // SMTP account username 
$mail->Password = "yourpassword";  // SMTP account password 

$mail->SetFrom('[email protected]', 'First Last'); 

$mail->AddReplyTo("[email protected]","First Last"); 

$mail->Subject = "PHPMailer Test Subject via smtp, basic with authentication"; 

$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test 

$mail->MsgHTML($body); 

$address = "[email protected]"; 
$mail->AddAddress($address, "John Doe"); 

$mail->AddAttachment("images/phpmailer.gif");  // attachment 
$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment 

if(!$mail->Send()) { 
    echo "Mailer Error: " . $mail->ErrorInfo; 
} else { 
    echo "Message sent!"; 
} 

のために働き、セキュリティで保護されたアプリ "をONにします。

+0

commnetに感謝しますが、require_once( '../ class.phpmailer.php')を追加しようとしました。ページ全体が動作していません – Xhulo

+0

エラーログでチェックしましたか?エラーログメッセージを投稿できますか? –

+0

http://www.earn.shortify.pw/New%20Text%20Document.txt – Xhulo

関連する問題