view raw
Edward Mpanza Edward Mpanza - 7 months ago 31
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 = ';';  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP    authentication
$mail->Username = '';                 // 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('', 'Mailer');
$mail->addAddress('', '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

mail('', 'New user: username', 'somebody registered');