Juergen Posted August 15 Share Posted August 15 Hello at all I encountered a strange issue when sending emails using the Wiremail class from a shared host (world4you.com). Short description of the problem I added the following code from the documentation for the WireMail class to one of my templates for testing purposes: $m = $mail->new(); $m->to('myemailadress@example.at') // will be replaced with my real mail addy ->from('testmail@test.at') ->subject('Message Subject') ->body('Optional message body in plain text') ->bodyHTML('<html><body><p>Optional message body in HTML</p></body></html>') ->send(); After loading a page with this template, the email should be sent to my email address, but I never receive an email. If I use the same code on my local Installation with XAMPP using Gmail as my mail Client everything works as expected. So I tried to figure out where the problem might be, and I discovered the following: The WireMail class contains the send() method, which is responsible for sending the email. There you will find the PHP mail function, which contains a header variable ($header). If I remove this header variable from the brackets, the email is sent; otherwise, it is not. But the email content will not be displayed properly without this header variable. Before removing the header variable: if(@mail($to, $subject, $body, $header)) $numSent++; After: if(@mail($to, $subject, $body)) $numSent++; The problem could therefore be due to an incorrect header. So I took a look at the function renderMailHeader() which is responsible for creating the mail header syntax. I found out that the email is only sent if the value of “From” in the header is enclosed in double quotation marks, otherwise it will not be sent (see figure below). This does not seem to be important on my local installation. By default, the "From" value (in this case "myemail@example.com) is not between quotes in the header. If I change this inside the renderMailHeader() function, the mail will be sent. Only to mention: There is no entry in the log files indicating that something went wrong. Does anyone else have the same problem on a shared host and know how to fix it? I don't want to use SMTP instead, though. I guess there must be a better solution than changing something in the code or the problem is not the header syntax. Perhaps the header is not the problem, but rather the problem is related to something else?!? Thanks in advance for your help and hints Link to comment Share on other sites More sharing options...
cwsoft Posted August 15 Share Posted August 15 Have you tried sending email via SMTP? Had a similar issue on one site. After switching to PHPMailer with SMTP, sending emails worked. Also ensure the from email uses your domain name. 1 Link to comment Share on other sites More sharing options...
Juergen Posted August 15 Author Share Posted August 15 Hello @cwsoft 1 hour ago, cwsoft said: Have you tried sending email via SMTP? No, I haven't, and I think it would work with SMTP, but as I already wrote, I want to use the standard mail function because it is more simple 😉 Link to comment Share on other sites More sharing options...
cwsoft Posted August 16 Share Posted August 16 Have you asked the provider if sending mails via PHP mail function respective system call sendmail (Linux) is supported/enabled and what kind of settings may be required? Perhaps they deactivated sendmail etc. 1 Link to comment Share on other sites More sharing options...
Juergen Posted August 17 Author Share Posted August 17 No, but I think there must be another cause than I have thought first. The strange thing is that I can send mails by using 2 of my modules with the WireMail class without problems on that host. Only the third module makes problems. I have solved this problem for now by using the WireMailSmtp module. Link to comment Share on other sites More sharing options...
Juergen Posted August 25 Author Share Posted August 25 I have found the cause for this strange behavior: This is specific to my hoster world4you.com, but the problem could occur on other hosters too. My hoster does not allow you to send mails from domains other than the website domain itself. For example: My domain is www.mysite.eu, then I can only send mails where the email address ends with the domain name (e.g. myemail@mysite.eu). When I try to send an email from a different email domain (e.g. gmail.com), the email is not sent. I have not found the solution to disable this behavior, so I must contact my Provider. I guess this could be a security feature of the provider. Link to comment Share on other sites More sharing options...
Juergen Posted August 25 Author Share Posted August 25 Here is the solution for this scenario: Instead of using only the "from" property, use the "replyTo" property too. 1) Use a sender email address that contains your domain instead of the actual sender address (for example use norply@mydomain.com, where mydomain.com is your site domain. $mail->from('noreply@mydomain.com'); 2) Add the actual sender address (for example john@gmail.com) to the replyTo property $mail->replyTo('john@gmail.com'); This will use the mail address of the actual user if you click on reply instead of "noreply@mydomain.com". I will add this to the module in the next update, so it should work on every host. 1 Link to comment Share on other sites More sharing options...
cwsoft Posted August 25 Share Posted August 25 On 8/15/2025 at 5:06 PM, cwsoft said: ... Also ensure the from email uses your domain name. 😀 2 Link to comment Share on other sites More sharing options...
Juergen Posted August 25 Author Share Posted August 25 @cwsoft you were absolutely right - this was the reason 😛 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now