dongou0524 2018-06-18 16:18
浏览 47


This question already has an answer here:

i've searched for hours for a solution but i just don't get it. I'm fairly new to PHP, I'm doing a project where i need an email to be sent, the problem is that I can't figure how to do it. Others who had the same problem, fixed it by configuring the php.ini and the sendemail.ini

This is my current code for testing:


$subject="Hi There!!";
$body="This is a demo email sent using PHP on XAMPP";
if (mail($to,$subject,$body)){
 echo "Mail sent successfully!";
 echo "Mail not sent!";


I receive the "Mail sent successfully" but there is nothing on my inbox, not even on the spam folder. I also tried to use PHPMailer but (like i said) im fairly new to php and i don't get how to enable it on my code. What do you guys think?

  • 写回答

1条回答 默认 最新

  • douba4275 2018-06-18 16:25
    require 'PHPMailer/PHPMailer.php';
    require 'PHPMailer/Exception.php';
    require 'PHPMailer/OAuth.php';
    require 'PHPMailer/POP3.php';
    require 'PHPMailer/SMTP.php';
    $mail = new PHPMailer;
    // SMTP configuration
    $mail->Host = '';
    $mail->SMTPAuth = true;
    $mail->Username = '';
    $mail->Password = '******';
    $mail->SMTPSecure = 'tls';
    $mail->Port = 587;
    $mail->setFrom('', 'CodexWorld');
    $mail->addReplyTo('', 'CodexWorld');
    // Add a recipient
    // Add cc or bcc 
    // Email subject
    $mail->Subject = 'Send Email via SMTP using PHPMailer';
    // Set email format to HTML
    // Email body content
    $mailContent = "<h1>Send HTML Email using SMTP in PHP</h1>
        <p>This is a test email has sent using SMTP mail server with PHPMailer.</p>";
    $mail->Body = $mailContent;
    // Send email
        echo 'Message could not be sent.';
        echo 'Mailer Error: ' . $mail->ErrorInfo;
        echo 'Message has been sent';

    php mailer library

    follow following link to understand php mailer

    directory structure

    -root (your proj root directory from where your php file runs)
      -index.php (file with above code)
      -PHPMailer(folder contain mailer library)
         -php mailer files (go to git repo, download and copy all files from src folder)
    本回答被题主选为最佳回答 , 对您是否有帮助呢?



  • ¥20 用vivado写数字逻辑实验报告撰写,FPGA实验
  • ¥15 为什么shp文件会有这种小方块?
  • ¥15 ecplise在连接数据库时显示加载驱动成功但是数据库连接失败
  • ¥15 visionmaster启动失败,提示为“机器不满足授权而被禁用”
  • ¥15 IDEA中圈复杂度如何具体设置
  • ¥50 labview采集不了数据
  • ¥15 Multisim红外倒车雷达仿真中距离问题
  • ¥15 请上面代码做什么处理或什么混淆
  • ¥15 英雄联盟自定义房间置顶
  • ¥15 W5500网线插上无反应