1

I am new to PHP and trying to send an email with PHP script.

I did change "php.ini" settings to SMTP = "in.mailjet.com" smtp_port= 25 auth_username="abc" auth_password="abc" sendmail_from = "abc@abc.com"

Simple HTML file to call php file is form name="contactform" method="post" action="PHPMailer/email.php"
style="padding-left:5%;"> <td colspan="2" style="text-align:center"> <br> <input class="btn btn-info" type="submit" value="Download">

email.php file

    require 'class.phpmailer.php';
    $mail = new PHPMailer(true);
    $mail->IsSMTP();
    $mail->Host="in.mailjet.com";
    $mail->SMTPAuth = true;
    $mail->Username = 'abc';
    $mail->Password = 'abc';
    $mail->SetFrom('abc','Your Name');
    $mail->AddAddress('jibran.ishtiaq@runyourfleet.com','Their Name');
    $mail->Subject = 'Your email from PHPMailer and Mailjet';
    $mail->MsgHTML('This is your email message.");
    $mail->Send();

I am trying to send email from IIS server(test server), but I am not been able to send please help me out or let me know what I am missing.

Thank You

Jibran
  • 99
  • 1
  • 1
  • 8
  • 2
    well it could be any number of things, but the SO syntax highligher should help you spot a mismatched quote in the second to last line – Steve Jun 16 '15 at 11:56
  • Sorry steve could you help me to solve this problem. – Jibran Jun 16 '15 at 12:00
  • 1
    Well for a start fix that quote `...your email message.");` should be `...your email message.');` Note the single, not double quote – Steve Jun 16 '15 at 12:01
  • Does this answer your question? [How to send email with SMTP in php](https://stackoverflow.com/questions/25909348/how-to-send-email-with-smtp-in-php) – SendETHToThisAddress Jan 20 '22 at 21:35

1 Answers1

1

Try below code:

require 'class.phpmailer.php';

$mail = new PHPMailer();

$mail->isSMTP(); // send via SMTP

//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
//$mail->SMTPDebug = 2;

$mail->Host = $host; //SMTP server
$mail->Port = $port; //set the SMTP port; 587 for TLS
$mail->SMTPSecure = 'tls'; // secure transfer enabled REQUIRED for Gmail

if (strlen($username)) {
    $mail->SMTPAuth = true;
    $mail->Username = $username;
    $mail->Password = $password;
} else {
    $mail->SMTPAuth = false;
}

$mail->From = $from; // FROM EMAIL
$mail->FromName = $fromName; // FROM NAME
$mail->addAddress($to);
$mail->addReplyTo($from);

$mail->IsHTML($html);

$mail->Subject = $subject; // YOUR SUBJECT
$mail->Body = $message; // YOUR BODY
$mail->addAttachment($attachment); // YOUR ATTACHMENT FILE PATH

if ($mail->send()) {
    echo "Message Sent";exit;
} else {
    echo "Message Not Sent<br>";
    echo "Mailer Error: " . $mail->ErrorInfo;exit;
}  

Note: Replace all variables with yours appropriately

Dhaval Bharadva
  • 3,053
  • 2
  • 24
  • 35
  • where it would be getting information of $host, $port, $username and $password from (is it from php.ini) – Jibran Jun 16 '15 at 12:15
  • @Jibran its your variables you can replace or set static there. `$host`='in.mailjet.com', `$port` = '25' OR '456' OR '587', `$username` = 'your email' and `$password` = 'Your password' – Dhaval Bharadva Jun 16 '15 at 12:18
  • " still same result just a blank page. I save email.php file under PHPMailer. Changed php.ini settings but still same result. What else I am missing to run this script in IIS server". – Jibran Jun 16 '15 at 12:32
  • @Jibran no need to change in php.ini code above code is working fine for me. you should track the error. – Dhaval Bharadva Jun 16 '15 at 12:34
  • what are your php.ini settings for smtp. – Jibran Jun 16 '15 at 12:35
  • @Jibran i don't remember but its default which was at the time of installation. – Dhaval Bharadva Jun 16 '15 at 13:14
  • FYI this example uses basic authentication, which is now deprecated. Checkout this link for how to use modern authentication https://github.com/PHPMailer/PHPMailer/wiki/Using-Gmail-with-XOAUTH2 – SendETHToThisAddress Jan 20 '22 at 21:49