2013-12-15 112 views
-1

即時通訊使用wamp,我想從一個教程在YouTube上測試一個電子郵件功能,但它不會發送,我得到的所有代碼都是正確的,它發送了您的電子郵件的消息已經送走了。我甚至改變了php.ini文件 SMTP = smtp.gmail.com sendmail_from = [email protected] 任何建議我如何發送電子郵件從本地主機到我的gmail

如果u能可以ü給我寫一封電子郵件功能,這裏是我的 這是一個忘記密碼的事情我做即時通訊試圖向用戶發送電子郵件的新密碼

<?php 
    if (isset($_GET['success']) === true && empty($_GET['success']) === true) { 
?> 
    <p>Thanks, we've emailed you.</p> 
<?php 
} else { 
$mode_allowed = array('email', 'password'); 
if (isset($_GET['mode']) === true && in_array($_GET['mode'], $mode_allowed) === true) { 
    if (isset($_POST['email']) === true && empty($_POST['email']) === false) { 
     if (user_exists($_POST['email']) === true) { 
      recover($_GET['mode'], $_POST['email']); 
      header('Location: recover.php?success'); 
      exit(); 
     } else { 
      echo '<p>Ooops, we couldn\'t find that email address</p>'; 
     } 
    } 
?> 

function recover($mode, $email) { 
    $mode = sanitize($mode); 
    $email = sanitize($email); 

    $user_data = user_data(user_id_from_email($email),'user_id', 'first_name', 'username'); 

    if ($mode == 'username') { 
     email($email, 'Your username', "Hello " . $user_data['first_name'] . ",\n\nYour username is: ". $user_data['username'] . "\n\n-phpacademy"); 
    } else if ($mode == 'password') { 
     $generated_password = substr(md5(rand(999, 999999)), 0, 8); 
     change_password($user_data['user_id'], $generated_password); 
     email($email, 'Your password recovery', "Hello " . $user_data['first_name'] . ",\n\nYour pasword is: ". $generated_password . "\n\n-phpacademy"); 
    } 
} 

function email($to, $subject, $body, $headers) { 
    mail($to, $subject, $body, $headers); 
} 
+0

如果您只是想測試從您的代碼發送的電子郵件,則可以始終使用[DevNullSMTP](http://www.aboutmyip.com/AboutMyXApp/DevNullSmtp.jsp)等工具來發送電子郵件,郵件在您的本地機器上。 – ajp15243

回答

0

其次this guide它會幫助你渡過難關。 確保你除了使用projectpier之外還有其他的一切,你不需要它。您將使用Php發送郵件。

示例PHP代碼:

$header = "From: ".$from_name." <".$from_mail.">\r\n"; 
$header .= "Reply-To: ".$replyto."\r\n"; 
    if (mail($mailto, $subject, $message, $header)) { 
     echo "Mail successfully sent with given data"; // or use booleans here 
    } else { 
     echo "Mail sending failed! Please make sure all data is correct and you are connected to the internet"; 
    } 

確保您設置的所有變量正確

0

至於電子郵件的發送而言,我會建議使用PHPMailer的。您可以在phpmailer

function send_email($recipient, $sender_email,$sender_name, $subject, $message){ 
require_once("phpmailer/class.phpmailer.php"); 
$mail = new PHPMailer(); 
$body = $message; 
$mail->Host   = 'smtp.googlemail.com'; 
$mail->SMTPAuth  = true; 
$mail->Username  = 'your gmail id'; 
$mail->Password  = 'your gmail password'; 
$mail->IsSMTP(); 
$mail->FromName  = $sender_name; 
$mail->Port   = 465; 
$mail->SMTPSecure = 'ssl'; 
$mail->From   = $sender_email; 
$mail->Subject  = $subject; 
$mail->AltBody  = strip_tags($message); 
$mail->MsgHTML($body); 
$mail->AddAddress($recipient); 


if (! $mail->Send()) 
{ 
    return false; 
} 
else 
{ 
    return true; 
} 

}

得到同樣我想這將解決您的問題.. 另外,我建議你遵循先找出這個問題的辦法。首先檢查您的郵件功能是否正常工作,只需傳遞硬編碼值即可。一旦您確認了相同的情況,然後通過您的表單/代碼傳遞值,然後再次檢查問題。

相關問題