Edward Mpanza Edward Mpanza - 19 days ago 4x
PHP Question

Sending Database User Info Into Email

I'm currently working on a website with a login and register feature. Now, the client wants all the user info sent to him via email and I have no idea on how to send the database user info into his email. If anyone has an idea on how I can do this, please assist me.


You could use a mailer library to send to user data to the client. I have personally used PHPMailer before.

Here is an example from their github page:

$mail = new PHPMailer;
$mail->isSMTP();                                      // Set mailer to use     SMTP
$mail->Host = 'smtp1.example.com;smtp2.example.com';  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP    authentication
$mail->Username = 'user@example.com';                 // SMTP username
$mail->Password = 'secret';                           // SMTP password
$mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587;                                    // TCP port to connect to
$mail->setFrom('from@example.com', 'Mailer');
$mail->addAddress('joe@example.net', 'Joe User');     // Add a recipient
$mail->Subject = 'Here is the subject';
$mail->Body    = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent';

Alternatively there is the php mail function http://php.net/manual/en/function.mail.php.

mail('client@email.com', 'New user: username', 'somebody registered');