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 I'm not sure if there's some problem with my code or x10hosting doesn't allow it.

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

MH

Check with your host. Perhaps port 587 is blocked.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.