# PHP en GMAIL In (any) project directory: ``` composer require phpmailer/phpmailer ``` ### Create app password in Google **google account - security 0 2-Step Verification - App passwords** ### emailer PHP code (this will accept a posted form and email all form fields). ```PHP $value) { $emailContent .= "$key: $value\n"; } $mail = new PHPMailer(true); try { // Server settings $mail->isSMTP(); $mail->Host = 'smtp.gmail.com'; $mail->SMTPAuth = true; $mail->Username = $gmailUsername; $mail->Password = $gmailPassword; $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; $mail->Port = 587; // Recipients $mail->setFrom($gmailUsername, 'Form Submission'); $mail->addAddress($recipientEmail); // Content $mail->isHTML(false); $mail->Subject = 'New Form Submission'; $mail->Body = $emailContent; $mail->send(); echo 'Message has been sent'; } catch (Exception $e) { echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}"; } } ?> ``` ### Form example ```HTML