Jump to content

Recommended Posts

What's wrong with my code? It just won't send emails. It worked before when not using wiremailSMTP but now it stops. This is used in a contact form.

It has to be the code because when I run a test in the module, it works fine and the email reaches me.
Even the Promailer-Newsletters using WireMail SMTP work fine now.
Even when I put some debug code on the template to be send to me via email with every email, that email reaches me. 
But somehow the email in question, send with contact form does not.
BTW if-condition works fine cause redirection works as well.

Here's my code:

if (isset($_POST['sendform']) && $captcha->verifyResponse() === true) :

    $givenname = $input->post->text('givenname'); 
    $familyname = $input->post->text('familyname'); 
    $fullname = $givenname.' '.$familyname;
    $fullname = ucwords($fullname);

    $email = $input->post->email('emailaddress'); 
    $subject = $input->post->text('subject'); 
    $message = $input->post->text('message'); 

    $m = wireMail();
    $m->to('myemail@mydomain.com', 'my Name');
    $m->from($email, $fullname);
    $m->subject($subject);
    $m->body($message);
    $m->send();
    $session->redirect($pages->get("/kontakt/danke/")->url);

endif;

I recently installed a SSL certificate on the webserver, but that should be irrelevant, right?

Further settings:

port: 587
Allow Connection without Authentication: no
SMTP User and SMTP Password provided
Use Start-TLS: no
TLS Crypto method: 1.2
Use SSL: no
Allow self signed certificated: no

Thanks for help!

 

Share this post


Link to post
Share on other sites

OK I just realised that an email send via my contact form only go through when $email is the actual SMTP-user's email address

$m->from($email, $fullname);

So I understand that by enforcing authentication when sending an email, the ->from email needs to be the authentified user's email. Thus the email that I receive can't and won't have the user's email. That's only possible with a connection without authentication? So I need to include the email somewhere else, in the email's body? So "replying" is not possible as such.

Is my assessment accurate?

Share this post


Link to post
Share on other sites
56 minutes ago, fruid said:

So I understand that by enforcing authentication when sending an email, the ->from email needs to be the authentified user's email.

In theory, no, you can use any field you want for the From field in the e-mail. In practice however, many email providers will block this, as it's essentially spoofing. And even if your provider doesn't reject emails like this entirely, they will probably go directly to the spam folder, as your server probably is not authorised to send mail from this domain (using SPF, DKIM or similar methods). The mails might even be rejected entirely, depending on DMARC records.

And for good reason – you wouldn't want just anybody to be able to send spam that appears to have been sent from your address, right?

Quote

That's only possible with a connection without authentication?

You shouldn't send unauthenticated emails, and by the way you also shouldn't send emails without SSL – but that's a separate issue.

56 minutes ago, fruid said:

So "replying" is not possible as such.

Yes, it is. That's what the reply-to field in an email is for. This way, you can have a sender address (From field) that's clearly coming from your domain (something like no-reply@your-domain.com) and a different recipient for answers, which is the correct way to approach this.

That said, I have encountered one hosting provider that blocks emails where either the from OR the reply-to email don't belong to a domain that is registered with that provider. In this case, you'd have to find a workaround, like sending the email to both recipients and instructing them to hit reply all. Or integrate messaging into your application instead of using email. Alternatively, you might use mailto links with pre-filled recipient, subject line and body and instruct your users to send their own mail. Which might be cleaner in terms of email security / authentication, though it depends on your application.

  • Like 1

Share this post


Link to post
Share on other sites
23 minutes ago, MoritzLost said:

many email providers will block this, as it's essentially spoofing

Yes, our provider actually does seem to block it at least when using Authentication, regardless of whether or not I "allow" sending without.
And that's good, I must say I always found it strange that it's possible in theory to send an email from whatever email, given the right insecure email server.

25 minutes ago, MoritzLost said:

Yes, it is. That's what the reply-to field in an email is for. This way, you can have a sender address (From field) that's clearly coming from your domain (something like no-reply@your-domain.com) and a different recipient for answers, which is the correct way to approach this.

Yes, thanks, I found the ->replyto() method and it works like a charm. Just wondering now, I agree noreply@ is a very good practice, but since WireMail needs to be logged in with the sender's email-account, I need to create a noreply@ email-address and mailbox on my email-server?

Thanks so far

Share this post


Link to post
Share on other sites
2 hours ago, fruid said:

Just wondering now, I agree noreply@ is a very good practice, but since WireMail needs to be logged in with the sender's email-account, I need to create a noreply@ email-address and mailbox on my email-server?

Not necessarily. The username of your email account is independent from the sender address – this is why, for example, you can have one email account with multiple associated email addresses. Though some providers don't make that distinction clear, and nowadays your username is usually the primary email address, so most people (in my experience) are not aware that those are two different things.

WireMailSmtp needs the username of the account to log in, and often this is the same as the sender address, but it doesn't have to be. This is why you can specify the username and sender address separately. WireMailSmtp doesn't care about the domain the sender address belongs to, any restrictions regarding that are done by the mail provider.

What matters for verification and spam prevention is the domain you're sending from. If you're sending from @your-domain.com and you've properly set up the SPF and DKIM records for your mail server, your mail server can send emails from every address @your-domain.com without problems. Of course, any mail provider / server tool can add any restrictions for sender addresses they want on top of that. For example, if you send your Email through Gmail, it probably won't let you use a sender address that doesn't belong to your account. So it comes down to what email provider you're using.

  • Like 1

Share this post


Link to post
Share on other sites

@MoritzLost

You seem to have quite some experience with PW's mail functions. Would you have time and feel like taking a closer look at my setup?

Share this post


Link to post
Share on other sites

OK so I'm in a pickle now, no email module seems to work.

As mentioned above, I had been using the php mail function before, which worked ok for some time, but then not anymore.

So I learned about WireMail SMTP and that sending via SMTP is always better in terms of spam protection. As required by the host (World4You), I setup an authenticated user in the settings with port 587. This worked fine for some time, now it doesn't anymore.

Now I installed SwiftMail which also has test connection and test email features. I tried these tests, both are claimed successful, no errors, but no emails get received. This is scary! Is there any mail module that actually works? There are no errors neither on PW nor on the server, just success messages from PW.

How to debug this stuff? Need help urgently!

Share this post


Link to post
Share on other sites

Thanks but no, that doesn't seem to be the problem. I'm now using WireMailPHPMailer which works fine. The contact form at least which uses the code and API I wrote on the contact form's template file. So that's good, at least I know the module is working and the connection to the SMTP server is established. Rock-mail-logger is also good as a log-tool.

Still having issues with sending newsletters with Promailer via WireMailPHPMailer though, which doesn't use any custom code AFAIK, just the settings in the module. But that's to be discussed in the VIP support.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By ngrmm
      i'm trying to attach a .ics-file to a mail
      The Page send sends out the email but only download the ics-file. Email has no attachments.
      // event ID $eventID = $input->get('eventID','int'); $event = $pages->get($eventID); // config $testEmail = $event->event_mail_test_adress; $fromEmail = $event->event_mail_from; $fromName = $event->event_mail_from_name; $emailSubject = $event->event_subject; // .ics $filename = $event->name; header('Content-Encoding: UTF-8'); header('Content-type: text/calendar; charset=utf-8'); header("Content-Disposition: attachment; filename={$filename}.ics"); // fetch start date $event_start_ts = $event->getUnformatted("date_start"); // build the .ics data $ical_data = 'BEGIN:VCALENDAR'; $ical_data .= "\r\n"; $ical_data .= 'VERSION:2.0'; $ical_data .= "\r\n"; $ical_data .= 'CALSCALE:GREGORIAN'; $ical_data .= "\r\n"; $ical_data .= 'METHOD:PUBLISH'; $ical_data .= "\r\n"; $ical_data .= 'BEGIN:VEVENT'; $ical_data .= "\r\n"; $ical_data .= 'SUMMARY:'.$event->title; $ical_data .= "\r\n"; $ical_data .= 'UID:' . md5(uniqid(mt_rand(), true)) . '@'.$config->httpHost; $ical_data .= "\r\n"; $ical_data .= 'CLASS:PUBLIC'; $ical_data .= "\r\n"; $ical_data .= 'STATUS:CONFIRMED'; $ical_data .= "\r\n"; $ical_data .= 'DTSTART:'.date('Ymd', $event_start_ts).'T'.date("His", $event_start_ts); $ical_data .= "\r\n"; $ical_data .= 'DTSTAMP:'.date('Ymd').'T'.date('His'); $ical_data .= "\r\n"; $ical_data .= 'LOCATION:'.$event->venue; $ical_data .= "\r\n"; $ical_data .= 'URL:'.$event->httpUrl; $ical_data .= "\r\n"; $ical_data .= 'END:VEVENT'; $ical_data .= "\r\n"; $ical_data .= 'END:VCALENDAR'; // HTML BODY ob_start(); include('./_inc/emailbody.inc'); $emailBody = ob_get_clean(); // send email $m = new WireMail(); $m->to($testEmail); $m->from($fromEmail, $fromName); $m->subject($emailSubject); $m->bodyHTML($emailBody); $m->attachment($ical_data); $m->send();  
    • By ngrmm
      I have a page which sends out an email based on queries in the url
      <?php // event ID $eventID = $input->get('eventID','int'); $event = $pages->get($eventID); // config $adminEmail = "events@test.com"; $fromEmail = "noreply@test.com"; $fromName = "test"; $emailSubject = "Test Email"; // HTML BODY $emailBody = ""; // HOW TO ??? … // send mail $m = new WireMail(); $m->to($adminEmail); $m->from($fromEmail, $fromName); $m->subject($emailSubject); $m->bodyHTML($emailBody); $m->send(); ?> The email body is a bit complex: standard html/css tables and some php (pw variables).
      I put my emailbody (html) in a seperate file emailbody.inc but don't know how to include it?
       
    • By Mithlesh
      Hi there,
      My form is not getting submitted, it is showing:
      Unable to verify successful email delivery of this form submission.
      Attaching for your reference as well: 

      In the Backend, it is showing Connection timed out with smtp.gmail.com
      Pl guide me how to resolve that
    • By abdulqayyum
      hello processwire community,
      i am using LoginRegister module for front-end user registration. i am facing an issue verification email not receiving while WireMailSmtp is working perfectly and user receives message
      "Thank you, a confirmation code has been emailed to you. When you receive the email, click the link it contains, or paste the confirmation code below."
      received this message in front-end but does not receive any email relevant it.
      please help me in this case how i can solve it.
      Please check screen shots for SMTP test and message which receives user.
      Thanks AbdulQayyum,

      First screenshot SMTP test message, second when user receives message after clicking register button.
×
×
  • Create New...