-1

I have hosted my website on Plesk Hosting and was working on submitting the contact form. Installed PHP Mailer using composer. First I tried to send email using Gmail SMPT server it worked fine Second I tried to send email using my webhosting SMTP Server it is not working for me

$mail->Host = 'webmail.abc.in';      //host
$mail->SMTPAuth = false;              
$mail->Username = '******@abc.in';    
$mail->Password = '*******';              
$mail->SMTPSecure = 'tls';
$mail->Port = 25;      

I tested the SMPT server using SMTPER . it could send email using same credentials.

i dont know where the issue is..

is there any other library other then phpmailer??

Pramit Sawant
  • 682
  • 1
  • 9
  • 17

3 Answers3

1
$mail->SMTPAuth = true;

As simple as that, I think.

You said you have tested the credentials on SMTPer,

I'm sure you checked the "Use authentication" checkbox.

Maybe you thought you could make it false because you are not using SSL,

But this is about user authentication, not about encrypted communication.

Adem Tepe
  • 564
  • 5
  • 10
  • i tried both using authentication and without authentication, In SMTPer when authentication is checked you don't require username and password i guess. – Pramit Sawant Nov 19 '18 at 09:44
  • @PramitSawant I see. Have you checked the SMTP error message or server's error log? Can you please share it? Note: when authentication is checked it is "required" to enter username and password – Adem Tepe Nov 19 '18 at 09:53
1

This is a example of of code I'm using with gmail. Tested it with webhosting SMTP and worked as well.

`           $mailMsg = ADD_MAIL_MESSAGE_HERE;
            $mailto = ADD_TO_ADDRESS_HERE;
            $mail = new PHPMailer\PHPMailer\PHPMailer();
            $mail->IsSmtp();
            $mail->SMTPDebug = 0;
            $mail->SMTPAuth = true;
            $mail->SMTPSecure = 'ssl';
            $mail->Host = 'smtp.gmail.com';
            $mail->Port = 465;
            $mail->IsHTML(true);
            $mail->CharSet = 'UTF-8';
            $mail->Username = ADD_USERNAME_HERE;
            $mail->Password = ADD_PASSWORD_HERE;
            $mail->SetFrom(ADD_FROM_ADDRESS_HERE);
            //-------------------------------------------
            $mail->Subject = ADD_MAIL_SUBJECT_HERE;
            $mail->Body = $mailMsg;
            $mail->AddAddress($mailto);
            $mail->SMTPOptions = array(
                'ssl' => array(
                    'verify_peer' => false,
                    'verify_peer_name' => false,
                    'allow_self_signed' => true
                )
            );
`
1

Are you using a Shared Hosting with Plesk? If yes, then this can probably be a port block issue (exact reason you will get only in the maillog). Looking at your code, I can see that in case of your local SMTP testing you are using port 25 while in case of Gmail it's 465.

By default, most of the shared hosting providers block the outgoing SMTP connection on port 25. This is done in order to protect the network and infrastructure from Spamming. If this is the case, then you need to contact their support to unblock the port or use some port free mode of email sending. Means instead of connecting over SMTP, connect over HTTP API for sending emails.

Dibya Sahoo
  • 839
  • 3
  • 9
  • 30