Email Sender

Results 1 to 12 of 12
  1. #1
    Proficient Member Jiq is offline
    MemberRank
    Nov 2015 Join Date
    MalaysiaLocation
    174Posts

    sad Email Sender

    Hello,

    I am gonna make email system for forgot password form, so it will send email when we request for password reset. How can I make mail() work success ? Actually I am from localhost.

    Regards,
    Jiq


  2. #2
    Member Aamiainen is offline
    MemberRank
    Aug 2016 Join Date
    FinlandLocation
    83Posts

    Re: Email Sender


  3. #3
    Making a come back NickHough is offline
    MemberRank
    Nov 2009 Join Date
    United KingdomLocation
    397Posts

    Re: Email Sender

    If you want something that is better then PHP's built in mail functions, then i would recommend PHPMailer -> https://www.sitepoint.com/sending-emails-php-phpmailer/

    The following method is also an example used form my server.
    Spoiler:

    function SendMail( $email, $response, $subject, $fromemail )
    {
    require_once './Mail/PHPMailerAutoload.php';

    $mail = new PHPMailer;

    //$mail->SMTPDebug = 3; // Enable verbose debug output

    $mail->isSMTP(); // Set mailer to use SMTP
    $mail->Host = 'ex.mail.ovh.net;ex.mail.ovh.net'; // Specify main and backup SMTP servers
    $mail->SMTPAuth = true; // Enable SMTP authentication
    $mail->Username = $fromemail; // SMTP username
    $mail->Password = 'password'; // SMTP password
    $mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 587; // TCP port to connect to

    $mail->From = $fromemail;
    $mail->FromName = 'Democracy Games';
    $mail->addAddress($email); // Add a recipient

    $mail->isHTML(true); // Set email format to HTML

    $mail->Subject = $subject;
    $mail->Body = $response."<p><b>
    <p>----------------------------------------------------------------------------------------
    SIGNATURE/STATIC END GOES HERE";
    $mail->AltBody = $response."<p><b>
    <p>----------------------------------------------------------------------------------------
    SIGNATURE/STATIC END GOES HERE";

    if(!$mail->send())
    {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
    $string = "UPDATE ACCOUNT_TBL SET SET CanSend = 0 where email = (?)";
    $params = array($email);
    $query = sqlsrv_query($mssqlconAcc, $string, $params, array( "Scrollable" => SQLSRV_CURSOR_KEYSET ));

    return false;
    }
    else
    {
    echo 'Message has been sent';
    return true;
    }
    }
    Last edited by NickHough; 18-09-16 at 12:03 PM.

  4. #4
    Proficient Member Jiq is offline
    MemberRank
    Nov 2015 Join Date
    MalaysiaLocation
    174Posts

    Re: Email Sender

    Quote Originally Posted by NickHough View Post
    If you want something that is better then PHP's built in mail functions, then i would recommend PHPMailer -> https://www.sitepoint.com/sending-emails-php-phpmailer/

    The following method is also an example used form my server.
    Spoiler:

    function SendMail( $email, $response, $subject, $fromemail )
    {
    require_once './Mail/PHPMailerAutoload.php';

    $mail = new PHPMailer;

    //$mail->SMTPDebug = 3; // Enable verbose debug output

    $mail->isSMTP(); // Set mailer to use SMTP
    $mail->Host = 'ex.mail.ovh.net;ex.mail.ovh.net'; // Specify main and backup SMTP servers
    $mail->SMTPAuth = true; // Enable SMTP authentication
    $mail->Username = $fromemail; // SMTP username
    $mail->Password = 'Gingerhough123'; // SMTP password
    $mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 587; // TCP port to connect to

    $mail->From = $fromemail;
    $mail->FromName = 'Democracy Games';
    $mail->addAddress($email); // Add a recipient

    $mail->isHTML(true); // Set email format to HTML

    $mail->Subject = $subject;
    $mail->Body = $response."<p><b>
    <p>----------------------------------------------------------------------------------------
    SIGNATURE/STATIC END GOES HERE";
    $mail->AltBody = $response."<p><b>
    <p>----------------------------------------------------------------------------------------
    SIGNATURE/STATIC END GOES HERE";

    if(!$mail->send())
    {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
    $string = "UPDATE ACCOUNT_TBL SET SET CanSend = 0 where email = (?)";
    $params = array($email);
    $query = sqlsrv_query($mssqlconAcc, $string, $params, array( "Scrollable" => SQLSRV_CURSOR_KEYSET ));

    return false;
    }
    else
    {
    echo 'Message has been sent';
    return true;
    }
    }
    Thanks, it working success. but I don't get any email, I am using Gmail Account and Gmail SMTP. I also use that on my localhost.

    - - - Updated - - -

    Quote Originally Posted by Jiq View Post
    Hello,

    I am gonna make email system for forgot password form, so it will send email when we request for password reset. How can I make mail() work success ? Actually I am from localhost.

    Regards,
    Jiq

    I've do a lot of research. But it doesnt work

  5. #5
    Banned Montage is offline
    BannedRank
    Sep 2016 Join Date
    ⓩⓔⓝⓓLocation
    67Posts

    Re: Email Sender

    hi i use this one for email sender i don't know its work from you but should try it

    // Pear Mail Libraryrequire_once "Mail.php";


    $from = '<fromaddress@gmail.com>';
    $to = '<toaddress@yahoo.com>';
    $subject = 'Hi!';
    $body = "Hi,\n\nHow are you?";


    $headers = array(
    'From' => $from,
    'To' => $to,
    'Subject' => $subject
    );


    $smtp = Mail::factory('smtp', array(
    'host' => 'ssl://smtp.gmail.com',
    'port' => '465',
    'auth' => true,
    'username' => 'johndoe@gmail.com',
    'password' => 'passwordxxx'
    ));


    $mail = $smtp->send($to, $headers, $body);


    if (PEAR::isError($mail)) {
    echo('<p>' . $mail->getMessage() . '</p>');
    } else {
    echo('<p>Message successfully sent!</p>');
    }

  6. #6
    Making a come back NickHough is offline
    MemberRank
    Nov 2009 Join Date
    United KingdomLocation
    397Posts

    Re: Email Sender

    You will have to make sure you change the from email, password and the host.

    For gmail the host should be: smtp.gmail.com;smtp.gmail.com
    For gmail the port is: 465
    for gmail the SMTPSecure is: ssl

    I also would state, that is it never a good idea to send from Localhost, due to the fact that all emails sent from untrusted sender gets placed in the spam mail box, you are better using hotmail, gmail or buying an email account from a trusted sender like ovh.com

  7. #7
    Proficient Member Jiq is offline
    MemberRank
    Nov 2015 Join Date
    MalaysiaLocation
    174Posts

    Re: Email Sender

    Quote Originally Posted by Montage View Post
    hi i use this one for email sender i don't know its work from you but should try it
    Thanks, but where 'mail' class come ? Can I get the library. :)

    - - - Updated - - -

    Quote Originally Posted by NickHough View Post
    You will have to make sure you change the from email, password and the host.

    For gmail the host should be: smtp.gmail.com;smtp.gmail.com
    For gmail the port is: 465
    for gmail the SMTPSecure is: ssl

    I also would state, that is it never a good idea to send from Localhost, due to the fact that all emails sent from untrusted sender gets placed in the spam mail box, you are better using hotmail, gmail or buying an email account from a trusted sender like ovh.com
    I already tried yours. But this is the problem:
    Code:
    Message could not be sent.Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
    


    This is my gilew.php edit:
    [CODE]
    <?php
    require 'PHPMailer-master/PHPMailerAutoload.php';


    $mail = new PHPMailer;


    //$mail->SMTPDebug = 3; // Enable verbose debug output


    $mail->isSMTP(); // Set mailer to use SMTP
    $mail->Host = 'smtp.gmail.com;smtp.gmail.com'; // Specify main and backup SMTP servers
    $mail->SMTPAuth = true; // Enable SMTP authentication
    $mail->Username = 'Aidilayam360@gmail.com'; // SMTP username
    $mail->Password = 'password'; // SMTP password
    $mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 465; // TCP port to connect to


    $mail->From = 'Aidilayam360@gmail.com';
    $mail->FromName = 'Democracy Games';
    $mail->addAddress('hzxxq24@gmail.com'); // Add a recipient


    $mail->isHTML(true); // Set email format to HTML


    $mail->Subject = 'Password Reset';
    $mail->Body = "<p><b>
    <p>----------------------------------------------------------------------------------------
    SIGNATURE/STATIC END GOES HERE";
    $mail->AltBody = "<p><b>
    <p>----------------------------------------------------------------------------------------
    SIGNATURE/STATIC END GOES HERE";


    if(!$mail->send())
    {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
    /*
    $string = "UPDATE ACCOUNT_TBL SET SET CanSend = 0 where email = (?)";
    $params = array($email);
    $query = sqlsrv_query($mssqlconAcc, $string, $params, array( "Scrollable" => SQLSRV_CURSOR_KEYSET ));
    */


    return false;
    }
    else
    {
    echo 'Message has been sent';
    return true;
    }
    ?>

    All is right ? Thanks :)

  8. #8
    Making a come back NickHough is offline
    MemberRank
    Nov 2009 Join Date
    United KingdomLocation
    397Posts

    Re: Email Sender

    That sounds like gmail is preventing you from sending the email.

    The email address you are sending to has to be a valid one, otherwise it wont work.

    I would suggest opening your GMail account and sending an email to that recipient and seeing if they receive it. If not there's your problem.

  9. #9
    Proficient Member Jiq is offline
    MemberRank
    Nov 2015 Join Date
    MalaysiaLocation
    174Posts

    Re: Email Sender

    Quote Originally Posted by NickHough View Post
    That sounds like gmail is preventing you from sending the email.

    The email address you are sending to has to be a valid one, otherwise it wont work.

    I would suggest opening your GMail account and sending an email to that recipient and seeing if they receive it. If not there's your problem.
    Its work success when I compose from my account. Can you help me in another way ?

  10. #10
    Making a come back NickHough is offline
    MemberRank
    Nov 2009 Join Date
    United KingdomLocation
    397Posts

    Re: Email Sender

    I just read the GMail requires you to allow access to the account, login to your Gmail account and look for a setting that says enable “Less Secure Apps”.

    https://support.google.com/accounts/.../6010255?hl=en

    Hopefully it should work after letting less secure apps access your account (which by nature PHP mailing is regardless of how you wish to do it).

  11. #11
    Proficient Member Jiq is offline
    MemberRank
    Nov 2015 Join Date
    MalaysiaLocation
    174Posts

    Re: Email Sender

    Quote Originally Posted by NickHough View Post
    I just read the GMail requires you to allow access to the account, login to your Gmail account and look for a setting that says enable “Less Secure Apps”.

    https://support.google.com/accounts/.../6010255?hl=en

    Hopefully it should work after letting less secure apps access your account (which by nature PHP mailing is regardless of how you wish to do it).
    Already tried this before. but not working :"(

  12. #12
    Making a come back NickHough is offline
    MemberRank
    Nov 2009 Join Date
    United KingdomLocation
    397Posts

    Re: Email Sender

    What i recommend next is setting up a hotmail account and trying with that (google hotmail smtp config) then seeing if that works.

    Otherwise all i'd suggest is i try to fix it over team viewer for you, as i don't know what else could be wrong.



Advertisement