0
Well, first of all I want to say that I’ve searched everywhere but I haven’t found an answer that works.
I’m talking about the Phpmailler.
I need to send e-mails authenticated from the website.
But I have one more difficulty: the e-mail that sends (From) will not always be what passes on authentication (mailbox Mail Server) server.
Hospedo no UOL Host and when the e-mail is the same as the authentication works.
I was wondering if there’s a way around this problem.
Follow what I’ve done:
Obs.: class include is done in another file
In time: Another thing I’d like to know is how to set up an account like naoresponda@..
. for NAY receive messages equal we received e-mails there with sender nãoresponda
?
<?php
class EmailEnviarDao {
public function __construct() {}
public function enviaEmail($email, $constantes) {
$caixaPostalServidorNome = $constantes->getTituloSite();
$caixaPostalServidorEmail = "contato@".$constantes->getDominioSite();
$caixaPostalServidorSenha = "senha";
$enviaFormularioParaNome = $email->getNomeAlvo();
$enviaFormularioParaEmail = $email->getEmailAlvo();
$remetenteNome = $email->getNomeRemete();
$remetenteEmail = $email->getEmailRemete();
$assunto = $email->getAssunto();
$mensagem = $email->getDescricao();
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPDebug = 0;
$mail->Charset = 'utf8_decode()';
$mail->Host = 'smtp.'.substr(strstr($caixaPostalServidorEmail, '@'), 1);
$mail->Port = '587';
$mail->Username = $caixaPostalServidorEmail;
$mail->Password = $caixaPostalServidorSenha;
/*
$mail->From = $remetenteEmail;
$mail->FromName = utf8_decode($remetenteNome);
*/
$mail->From = $caixaPostalServidorEmail;
$mail->FromName = utf8_decode($caixaPostalServidorNome);
$mail->IsHTML(true);
$mail->Subject = utf8_decode($assunto);
$mail->Body = utf8_decode($mensagem);
$mail->AddAddress($enviaFormularioParaEmail,utf8_decode($enviaFormularioParaNome));
if($mail->Send()){
return array("success"=>1,"errors"=>"0K");
} else {
return array("success"=>0,"errors"=>$mail->ErrorInfo);
}
}
}
?>
It’s a good thing it doesn’t work. Did you think if Smtps accepted email from unauthorized accounts? In these cases you should always use an authorized login account, regardless of the FROM: email. That’s why many direct mails are identified as "From <[email protected]> VIA <[email protected]>" - Sending is one, but Mailer is another.
– Bacco
Maybe I’m so tired of trying I didn’t even realize the real purpose of the class. But and when the user who send an email to the site through the site type itself when receiving a link by email to access a special contact page we want that such message will depart the email from the site but knowing the email of who sent?
– Carlos Rocha
There are 3 "main" shipping addresses: FROM is the sender. SMTP needs a valid account. And reply-to is an alternative email for replies if it is different from from. Not all Iler accepts sending on behalf of third parties. It’s just that virtually every good host has some system for sending email locally, without needing external SMTP. You have to see what the best situation is for your case.
– Bacco
It is often the case to ask for hosting support how to proceed in such cases. As I step very far away from the one you use, I would not be able to help with the specific case, but I think they should have some kind of customer service and/or Helpdesk..
– Bacco
I get it. But yes. There’s a hosting email account that authenticates. What I want is for From to be anyone. And don’t get hitched to the e-mil of authentication.
– Carlos Rocha
It would be the case to test another SMTP, even if only for evaluation (example, a generic gmail account) to see if the problem persists. There at least eliminates the possibility of the problem being in the application.
– Bacco
already tested:> same problem.
– Carlos Rocha
But tested separating in the code? The problem of your code above is that you use the same variable in the 2 places, there will not work even.
– Bacco
In your case you have to
$mail->Username = '[email protected]'
, separate from from from from– Bacco
What do you mean? Did you see $mail->From there? has a set for the authentication account and that is working and a $mail->From line that is commented and that is really the email I want to send and that comes from the form.
– Carlos Rocha
Precisely. Separate things. Username does not have to use the same variable from. Username is always the correct SMTP account
– Bacco
But that’s what I’m talking about. If I put another email in the From, it’s a mistake. It only sends if the From is the same as the authentication. That is: this way it is sending. But only send with the from being the authenticator. If from is for example an email from my visitor sending to me, there is no way!
– Carlos Rocha
Looking at your code, the variable is the same. I don’t know if you tested what I said, but in Username you should test with a fixed string, and not a variable (I understood that if it differs does not send, but the question is also whether you are using the correct one when it differs)
– Bacco
I am telling you this, because I have never seen this problem happen in any of the mailers I use (google, outlook, Zoho, etc). and it’s very normal for me to use From other than authentication.
– Bacco
$casPostalServidorEmail gets contact@". $constants->getDominioSite() and $constants->getDominioSite() never changes. You’re telling me to take the $constants->getDominioSite() and put the correct address straight with a string?
– Carlos Rocha
No. I’m saying do
$mail->Username = '[email protected]';
no variable, regardless of the rest - here’s the email that worked. Even if the rest change– Bacco
if so, already tested tb and did not work. It is possible to post as a response a class Voce uses only masking the data?
– Carlos Rocha
I can’t promise, but if there’s time soon I’ll try to adapt your code to some of my accounts.
– Bacco
OK, I tried here, look back: 2018-05-18 21:58:10 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
– Carlos Rocha
Ai no longer has to do with password and user, nor did connect.
– Bacco
This code https://pastebin.com/xNeLW9Aw works (I did now, using your code as a base, but google does not consider From - However, if you give a $mail->Setfrom( 'email', 'name') what to put here is right in Reply-to - If I do not use SMTP, but mail( ) PHP, that’s 100% as you wanted. The only detail in this last case, It has to set the SPF record of DNS, not to be considered spam.
– Bacco
2018-05-19 00:17:12 CLIENT -> SERVER: EHLO localhost<br> 2018-05-19 00:17:12 CLIENT -> SERVER: STARTTLS<br> SMTP Error: Could not connect to SMTP host. <br> 2018-05-19 00:17:13 CLIENT -> SERVER: QUIT<br> 2018-05-19 00:17:13 <br> SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting<br>
– Carlos Rocha
It is still a problem connecting to your server. There is some data wrong (either the server name, or the port, or the method)
– Bacco
2018-05-19 01:03:15 CLIENT -> SERVER: EHLO localhost 2018-05-19 01:03:15 CLIENT -> SERVER: AUTH LOGIN 2018-05-19 01:03:15 CLIENT -> SERVER: Y29udgf0b0bmdw5lcmfyawfzyw9wzwryby5uzxquyni= 2018-05-19 01:03:15 CLIENT -> SERVER: Yxv0qwmditg= 2018-05-19 01:03:15 CLIENT -> SERVER: MAIL FROM:<[email protected]> 2018-05-19 01:03:15 CLIENT -> SERVER: RCPT TO:<[email protected]>
– Carlos Rocha
2018-05-19 01:03:15 SMTP ERROR: RCPT TO command failed: 553 5.7.1 <[email protected]>: Sender address Rejected: not owned by user [email protected] 2018-05-19 01:03:15 CLIENT -> SERVER: SMTP Error: The following quit failed: [email protected]: <[email protected]>: Sender address Rejected: not owned by user [email protected]
– Carlos Rocha
and now? Join the two messages ok?
– Carlos Rocha
Just one more remark both emails, the From and the authentication belong to the domain of the site and the boxes created
– Carlos Rocha