【问题标题】:Issues in sending email from localhost in xampp [duplicate]在xampp中从本地主机发送电子邮件的问题[重复]
【发布时间】:2015-08-07 20:20:08
【问题描述】:

推荐了很多,

我做了以下事情:

这里是 php.ini:

SMTP=smtp.gmail.com
smtp_port=587
sendmail_from = xx@gmail.com
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"

sendmail.ini:

smtp_server=smtp.gmail.com
smtp_port=25
smtp_ssl=auto
error_logfile=error.log
debug_logfile=debug.log
auth_username=xx@gmail.com
auth_password=xxyyxxyy
force_sender=xx@gmail.com

这里是前端代码:

        <form action="send.php" method="post" id="newsletter" name="newsletter">
            <input type="text" name="signup-email" id="signup-email" value="" />
        <button id="actbtn" class="btn btn-7 btn-7h icon-envelope">Subscribe!</button>
            <span class="arrow"></span>
        </form>
        <div id="response"></div>
    </div>

终于发送.php:

<?php

$host   = "localhost";
$dbname = "database-name";
$user   = "";
$pass   = "";

$email    = filter_var($_POST['signup-email'], FILTER_SANITIZE_EMAIL);
$datetime = date('Y-m-d H:i:s');

try {
    $db = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass);

    if (empty($email)) {
        $status = "error";
        $message = "The email address field must not be blank";
    } else if (!preg_match('/^[^0-9][A-z0-9._%+-]+([.][A-z0-9_]+)*[@][A-z0-9_]+([.][A-z0-9_]+)*[.][A-z]{2,4}$/', $email)) {
        $status = "error";
        $message = "You must fill the field with a valid email address";
    } else {
        $existingSignup = $db->prepare("SELECT COUNT(*) FROM signups WHERE signup_email_address='$email'");
        $existingSignup->execute();
        $data_exists = ($existingSignup->fetchColumn() > 0) ? true : false;

        if (!$data_exists) {
            $sql = "INSERT INTO signups (signup_email_address, signup_date) VALUES (:email, :datetime)";
            $q = $db->prepare($sql);
            $q->execute(
                array(
                    ':email' => $email,
                    ':datetime' => $datetime
            ));

            if ($q) {
$status = "success";
$message = "You have been successfully subscribed";
} else {
$status = "error";
$message = "An error occurred, please try again";
}
} else {
$status = "error";
$message = "This email is already subscribed";
}
    }

    $data = array(
        'status' => $status,
        'message' => $message
    );

    echo json_encode($data);

    $db = null;
}
    catch(PDOException $e) {
    echo $e->getMessage();
}
?>

所以当我在时事通讯表单中输入电子邮件时,我的邮件帐户中没有收到任何邮件。

我正在使用 xampp。

谁能帮帮我?

我还缺少什么?谢谢。

【问题讨论】:

  • 我发布了这个问题,也参考了这些链接......谢谢
  • 您是否在您的 php.ini 中删除了此行 extension=php_openssl.dll 之前的分号
  • 是的@SubhojitMukherjee..这个文件名是php5.ini ..不是php.ini ..
  • @john conde:我无法从您的链接中获得解决方案..

标签: php email xampp


【解决方案1】:

不要更改 php.ini 中的任何内容。使用phpmailer从本地发送邮件。
Downloadphpmailer

使用此代码-

require 'PHPMailer/PHPMailerAutoload.php';

$mail = new PHPMailer;

//$mail->SMTPDebug = 3;                               // Enable verbose  debug output

$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com';  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'gmailemail';                 // SMTP username
$mail->Password = 'gmailpassword';                           // SMTP password
$mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587;                                    // TCP port to connect to

$mail->From = 'from@gmail.com';
$mail->FromName = 'GOKU';
$mail->addAddress('qwe@qwe.com');     // Add a recipient
$mail->addAddress('qwe@qwe.com');               // Name is optional

// $mail->addReplyTo('info@example.com', 'Information');
// $mail->addCC('cc@example.com');
$mail->addBCC('qwe.qwe@gmail.com');

// $mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
// $mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
$mail->isHTML(true);                                  // Set email format to HTML
$mail->Subject = 'hello';
$mail->Body    = 'Hi<br>';
if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent';
}

希望这会有所帮助.. :)

表格-

<form action="send.php" method="post" id="newsletter" name="newsletter">
    <input type="text" name="signup-email" id="signup-email" value="" />
    <input type="submit" id="actbtn" class="btn btn-7 btn-7h icon-envelope" value="Subscribe!" name="subscribe">
    <span class="arrow"></span>
</form>

在send.php -

if(isset($_POST['subscribe'])){
    // write send mail code here
}

【讨论】:

  • 评论不用于扩展讨论;这个对话是moved to chat
  • 请问谁能帮帮我?谢谢
猜你喜欢
  • 1970-01-01
  • 2019-08-05
  • 2021-11-20
  • 2013-12-18
  • 2012-01-28
  • 2016-07-22
相关资源
最近更新 更多