SMTP Error: Could not authenticate.

lifelink

New Member
Messages
5
Reaction score
0
Points
0
I created a javascript registration form and when the user submits the form, a 'sendemail.php' file will send the data in the form to my gmail email account. The code from 'sendemail.php' is shown below:


Code:
$mail->IsSMTP();                          // Fixed.
    $mail->Host       = 'smtp.gmail.com';     // Or Hotmail.
    $mail->Port       = '587';                // Fixed.
    $mail->SMTPSecure = 'tls';                // Fixed.
    $mail->SMTPAuth   = true;                 // Fixed.
    $mail->Username   = 'email@gmail.com'; // Your username.
    $mail->Password   = 'password';       // Your password.
    $mail->Timeout    = 30;                   // Timeout 30 seconds.
    //////////////////////////




        $pname = $_REQUEST['pname'] ;
        $sex = $_REQUEST['sex'] ;
        $age = $_REQUEST['age'] ;
        $hosp = $_REQUEST['hosp'] ;
        $ic = $_REQUEST['ic'] ;
        $padd = $_REQUEST['padd'] ;
        $ptel = $_REQUEST['ptel'] ;
        $emname1 = $_REQUEST['emname1'] ;
        $emcon1 = $_REQUEST['emcon1'] ;
        $emname2 = $_REQUEST['emname2'] ;
        $emcon2 = $_REQUEST['emcon2'] ;
        $medcon = $_REQUEST['medcon'] ;
        $aller = $_REQUEST['aller'] ;
      




        $mail->SetFrom('email@gmail.com', 'General Registration'); // Your username.
                    $mail->AddAddress('email@gmail.com', 'Admin'); // Recipient.
                    $mail->Subject = 'Registration';
                    $mail->Body    = "\r\n Patient Name: " . $pname . "\r\n Sex: ". $sex . "\r\n Age: ". $age . "\r\n Hospital: "
                            . $hosp . "\r\n IC: " . $ic . "\r\n Address: " . $padd . "\r\n Contact: " . $ptel . "\r\n Emergency Contact Person 1: "
                            . $emname1 . "\r\n Emergency Contact 1 Tel: " . $emcon1 . "\r\n Emergency Contact Person2: " . $emname2
                            . "\r\n Emergency Contact 2 Tel: " . $emcon2 . "\r\n Medical Condition: " . $medcon . "\r\n Allergies: " . $aller;


                    $mail->Send();
                    echo '<p class="ok">Registration sent, Thank you!</p>';

The problem: It is not emailing the details to my email.

The error shown is :

Fatal error: Uncaught exception 'phpmailerException' with message 'SMTP Error: Could not authenticate.' in /home/lifelink/public_html/class/class.phpmailer.php:814 Stack trace: #0 /home/lifelink/public_html/class/class.phpmailer.php(705): PHPMailer->SmtpConnect() #1 /home/lifelink/public_html/class/class.phpmailer.php(576): PHPMailer->SmtpSend('Date: Wed, 25 J...', '? Patient Name:...') #2 /home/lifelink/public_html/sendemail.php(45): PHPMailer->Send() #3 {main} thrown in /home/lifelink/public_html/class/class.phpmailer.php on line814

I'm not well-versed in php, so is there another alternative to send the form data to my gmail email?

NOTE: I tested my code locally and it worked. The error only appeared after i uploaded the codes.

MH
 
Last edited:

ellescuba27

Member
Messages
273
Reaction score
3
Points
18
It's because you are using your Gmail. Use the x10hosting CPanel mail instead. You can create one by going to your Account Portal - http://x10hosting.com/portal - and logging in, then pressing, Access CPanel. Then, use the buttons to manage and create a new email for you using CPanel.
 
Top