T
T
Torawhite2016-02-09 17:03:08
PHP
Torawhite, 2016-02-09 17:03:08

How to work with PHPmailer?

I can't figure out how to send mail using PHP. Initially, I used the mail () function, but letters came only to yandex, to mail.ru (bk.ru), gmail.com - they do not come. I started searching the Internet for a solution to the problem and, in the end, I decided that it was worth trying PHPmailer. No indication HostSMTPAuthPortSMTPSecureUsernamePassword. If I understand correctly, then these parameters must be specified if you want to use not the default server for sending letters, but, for example, the yandex server. And, if you have a yandex account, then I must enter the data corresponding to my account in the fields described above. So I tried, but now the letter does not come anywhere at all! What did I misunderstand? Here is the code:

$mail = new PHPMailer();

        $mail->IsSMTP();
        $mail->Host       = 'smtp.yandex.ru';
        $mail->SMTPDebug  = 2;
        $mail->SMTPAuth   = true;
        $mail->Port       = '465';
        $mail->SMTPSecure = 'ssl';
        $mail->CharSet    = 'UTF-8';
        $mail->Username   = '[email protected]';
        $mail->Password   = '123';
        $mail->Subject    = $subject;
        $mail->Body       = $html_body;

        $mail->setFrom('[email protected]', 'mysite');
        $mail->AddAddress($to_address);

        $mail->Send();

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stalker_RED, 2016-02-09
@Stalker_RED

If you think that emails to gmail did not come due to incorrect settings - this is not entirely true.
Once upon a time, when the trees were big and the internet was small, emails could be sent by anyone to anyone. And now many mail servers want all sorts of digital signatures and certificates from the sender - they are fighting spam like that.
So you need either a correctly configured smtp server with all signatures and seals on the tail, or contact the administrator of this "default server" with the question "why do I not receive letters to gmail.com".

T
Torawhite, 2016-02-09
@Torawhite

Thank you Stalker_RED . But did I understand the principle correctly? Can I also send emails from my hosting server? I created a postal address there and, by analogy with the Yandex server, can I send it through the server of my hosting?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question