0

Hello guys I am trying to send the mail after user fills in the registration form and clicks the submit button. i have no clue what am i doing wrong but i dont receive any mails. Please help me!

<?php
if(isset($_POST['submit'])) 
{

$message=
'Name           :   ' .$_POST['firstname'].'        <br />

';
    require "phpmailer/class.phpmailer.php"; //include phpmailer class
      
    // Instantiate Class  
    $mail = new PHPMailer();  
      
    // Set up SMTP  
    $mail->IsSMTP();                // Sets up a SMTP connection  
    $mail->SMTPAuth = true;         // Connection with the SMTP does require authorization    
    $mail->SMTPSecure = "ssl";      // Connect using a TLS connection  
    $mail->Host = "smtp.gmail.com";  //Gmail SMTP server address
    $mail->Port = 465;  //Gmail SMTP port
    $mail->Encoding = '7bit';
    
     // Authentication  
    $mail->Username   = "holla@gmail.com"; // Your full Gmail address
    $mail->Password   = "blablabla"; // Your Gmail password
      
    // Compose

    $mail->Subject = "New Admission Enquiry Form";      // Subject (which isn't required)  
    $mail->MsgHTML($message);
  
    // Send To  
    
    $mail->AddAddress("jaganrao44@gmail.com", "Recipient Name"); // Where to send it - Recipient
    
    
    
    
    
    
    $result = $mail->Send();        // Send!  
    $message = $result ? 'Successfully Sent!' : 'Sending Failed!';      

}
?>
  • I read it somewhere that gmail will not accept any email from php. It will considered as spam or something like that – nabil arta Oct 21 '20 at 09:36
  • On the above, you may need to enable sending from "less secure apps" in your Gmail console. I have some VB stuff that sends email via gmail and have to do that. But, if I don't enable it, I do get an error message when I try to send. – droopsnoot Oct 21 '20 at 09:38
  • You don't seem to set a "from" address either, might that be an issue, or does PHPMailer use a default? – droopsnoot Oct 21 '20 at 09:40
  • Does this answer your question? [PHP mail function doesn't complete sending of e-mail](https://stackoverflow.com/questions/24644436/php-mail-function-doesnt-complete-sending-of-e-mail) – ADyson Oct 21 '20 at 09:40
  • I am very new to that php mail stuff can anyone guide step by step because im not sure where i have to start – Arturas Zavialovas Oct 21 '20 at 09:42
  • Does your code look like any of the examples that you followed when writing it? Any key differences? And have you looked in your gmail to see if it's complaining - sometimes it will send _you_ an email to tell you that something is trying to use it. – droopsnoot Oct 21 '20 at 09:51
  • If you look at the link I provided, the main answer there is already a very detailed guide. – ADyson Oct 21 '20 at 10:36

2 Answers2

0

you didn't put this :

$mail->charSet="UTF-8"; //for me it's utf-8
$mail->from="holla@gmail.com";

also check if your port are open (465) (you can also try 25 or 587)

745th
  • 61
  • 1
  • 5
-1
  1. Change your require to:
    use PHPMailer\PHPMailer\PHPMailer;
    use PHPMailer\PHPMailer\SMTP;
    
    require('PHPMailer/src/PHPMailer.php');
    require('PHPMailer/src/SMTP.php');
  1. Your isSMTP() function is with a capital I -> IsSMTP, change to lowercase 'i'.
  2. Add $mail->isHTML(true);
  3. Change $mail->SMTPSecure = "ssl" to $mail->SMTPSecure = HPMailer::ENCRYPTION_STARTTLS;
  4. Change port to 587

Refer to the example on PHPMailer's GitHub page for Gmail: https://github.com/PHPMailer/PHPMailer/blob/master/examples/gmail.phps

Refer to Google Docs to make sure your settings on Gmail are correct: https://support.google.com/mail/answer/7126229?hl=en

Overseer
  • 9
  • 2