How to Send Mails from Hosts that have mail function disabled - MAIL4EVERY1

ManzZup's Avatar author of How to Send Mails from Hosts that have mail function disabled - MAIL4EVERY1
This is an article on How to Send Mails from Hosts that have mail function disabled - MAIL4EVERY1 in PHP.

What is MAIL4EVERY1?



After long time, I got this very unusual idea to make something useful Basically I got fed up with my web host not allowing mail() feature and so MAIL4EVERY1. Mail4Every1 is a simple script that would allow any one to send emails even if the webhost allows the mail() or not or even it doesnt have a mail server at all. It is simply another function (zmail()) to sustitue for the default php mail() function.

How it Works?



It's just simple, no rocket science included . What the script does is to use a server that has already enabled the mail() function to act as the mail server of your host.

LOGIC:
  1. You call the zmail() function
  2. zmail() does a *hidden* AJAX call to another php script hosted in a host with mail() enabled
  3. The second host sends the message with the details given in the first one

That's it!

Lets begin the interesting part

Requirements


  1. mailer.php - The official script which contains the zmail() function
  2. A host with mail() enabled - Now you think why on the earth I would not use that host without doing all those hard stuff. The reason is many reliable web hosting providers doesn't allow the use of the mail() function as it can be easily abused. But there are plenty of free web hosting sites to help you in the task of doing it. Ex: I use zymic.com [I AM NOT TELLING ANYTHING WRONG ABOUT THIS HOST, JUST FOR THE EXPLANATION I USE IT]. I dont get the mail() function unless I give $10. I simple don't want to be paying as I cannot afford so I use another free host like freehostingcloud as the second host and use this script to send my mails.
  3. mail.php - This one should be there in the second host to be called from the first
Download the mailer.zip OR View Live Demo

Usage


  1. Download the zip file and extract, and you will get 3 files in the "zmail" directory. mailer.php, mail.php and jquery.js
  2. Upload mailer.php and jquery.js to web host from where you want to send mails.
  3. You need a free host that will allow to use the mail() function, I used the site freehostingcloud.com for mine. Make a new account there and upload the mail.php you found on the "zmail" directory.
  4. Now we need to call the zmail() function from another php script which will accept the POST data from a html form. You can find the index.php and mail2.php in the "demo" directory in the file you downloaded. Upload that to the SAME directory as before

    So we will make a simple a php script, it is just as calling the normal mail() function.

    mail2.php

    PHP Code:
    <?php
    include "mailer.php";

    if(isset(
    $_POST['send']))
    {
        
    $url "http://site.freehostingcloud.com/mail.php";
        
    $to=$_POST['to'];
        
    $from=$_POST['from'];
        
    $name=$_POST['name'];
        
    $sub=$_POST['sub'];
        
    $msg=$_POST['msg'];
        
    zmail($url,$to,$from,$name,$sub,$msg);
    }
    ?>
    NOTE: the usage of zmail() function;
    • $url - The path where the php script that do the actual mailing is [in the server where mail() is allowed]
    • $to - The reciever of the mail
    • $from - The sender's email [NOTE That some free hosting requires that the sender mail should be registered at the control panel first]
    • $name - The sender's name
    • $sub - The subject of the message
    • $msg - The mail content

    Now to call this script a little HTML form

    index.php

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>#Project : Mail4Every1 ZONTEK</title>
    </head>
    <body>
    *****************************************<br />
    #PROJECT MAIL4EVERY1<br />
    *****************************************<br />
    
    <form action="mail2.php" method="post">
    <table border="0">
    <tbody>
    <tr>
    <td>To :</td>
    <td><input type="text" name="to" /></td>
    </tr>
    <tr>
    <td>From :</td>
    <td><input name="from" type="text" /></td>
    </tr>
    <tr>
    <td>From Name :</td>
    
    <td><input name="name" type="text" /></td>
    </tr>
    <tr>
    <td>Subject :</td>
    <td><input name="sub" type="text" /></td>
    </tr>
    <tr>
    <td>Message :</td>
    <td><textarea cols="50" rows="15" name="msg"></textarea></td>
    </tr>
    <tr>
    <td></td>
    <td><input type="submit" value="Send" name="send" /></td>
    </tr>
    
    </tbody></table>
    </form>
    </body>
    </html>
  5. Upload these to the same drectory where mailer.php is
  6. Now browse your zymic URL http://site.zymic.com/mailtest you will find a simple form. Put the details in there, make sure you have done the steps corectly and push the Send button. You will be redirected to the mail2.php and then a little loading like sign and then everything done!
VIOLAAA!!
you will recieve your mail SOON...

Thats is basically the thing, but there are some things to be put
  1. THIS SCRIPT IS FOR EDUCATIONAL PURPOSES AND FOR THE USAGE FOR A GOOD REASON ONLY
  2. PLEASE DONOT USE THIS SCRIPT FOR SPAMMING
  3. THIS IS COMPLETELT FREE AND OPEN, DO WHAT EVER YOU LIKE BUT DONT FORGET TO MENTION US : http://zontek.zzl.org
  4. PLEASE DONATE ME TO PAY FOR MY ELECTICITY BILL : (if you like to donate my paypal is manzzup@gmail.com)
Attached Files
File Type: zip zmail.zip (51.7 KB, 125 views)
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
I am not sure if I get the idea of MAIL4EVERY1. You anyway need a host that is using mail function and so this is actually not sending email without mail function but using a different server.

I have few questions though.
  • How do you connect to second server? Do you use curl or anything like that?
  • Why not use smtp instead of mail function?
  • Is this not termed as spamming? Also does your mail come into inbox or goes into spam folder?
  • Why not use the hosting that provides mail function in the first place.
  • How do you handle the blacklisting of such free hosts?
ManzZup's Avatar, Join Date: May 2009
Skilled contributor
Why not use the hosting that provides mail function in the first place?

That's the one i was trying to clarify all along, it is like this. Many uses freehosting + a paid domain name these days. But most of these *free* hosting are not upto standard.
ex: assume that host1 is a very reliable, ad free hosting service but no mail() enabled
and host2 is a free service with all features but NOT reliable and even has ads
In a condition like this the user would like to have a combination of both, which is unlikely to be given free. As a foundation to make this combination MAIL4EVERY1 is there. You can use host1 as your host while using the mail() of host2. Hope it is clarified.


How do you connect to second server? Do you use curl or anything like that?

It is done using an AJAX request as the use of sockets would be disabled as well

Why not use smtp instead of mail function?

Even smtp needs the underling mail() function that is for php. So even if you use a relayer or a script like phpMailer it wont work as the mail() disabled

Is this not termed as spamming? Also does your mail come into inbox or goes into spam folder?

NO, this is not spamming but abusing this service may lead to spamming as well [That i'm trying to make a solution of]. The delivery of the mail relaye COMPLETELY on the way of host2(as of the previous example). The one i showed here will deliver it to the inbox. But there are certain free ones that deliver it to spam as well. For this i will be developing the use of smtp relayer like google from the other end (host2) for reliable mail delivery

How do you handle the blacklisting of such free hosts?

This is another issue when relating to the script. but the blacklisting will be done with/without the script as anyone can abuse the mail() function if it is enabled. But as for its effect on the MAIL4EVERY1 script assure you that it would be minimal as you can easily change your mailing host (host2) from the script so that if one is blacklisted another can be used. AND i am trying to develop a paid server in the future (if i got enough $$$ ) to make a free server available for the users of the script. If one i managed to provide this kind of a paid hoting for free ;
ex: user1 buys paid hosting with mail() and make it available for another 100 users to use
like that it can be developed but spamming will be a HUGE issue


AND thank alot shabbir for asking these questions as it will remove the doubts of other and i was just unable to explain the system well untill you asked those
thankx again
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Thanks for clarifying all but one question because I think I was not able to explain that question properly.

Quote:
Why not use smtp instead of mail function?
Now you are assuming that I am using the same server to send email using SMTP but normally SMTP is used on other server as well.

Let me give you an example.

Say I want to send emails from xyz.com and use external smtp server provider (Say Google) to send my emails and that way it does not matter if my xyz.com has mail enabled or not.

You are actually trying to re-invent the SMTP system with PHP mail function. Why not use SMTP of Google from reliable host1 instead of using it through a chain of hosts which are anyway unreliable.

Also one more fresh question.

What happens when host2 suddenly stops the mail function after understand it is being spammed.
ManzZup's Avatar, Join Date: May 2009
Skilled contributor
In your example, if the mail() is disabled in the hsot xyz.com, there's no way sending mails from the host. That means suppose you have a certain forum script that uses the mail() function to authenticate users by sending email after registration. If you use Google SMTP relayer, you have to have a script that would use the relayer and again the script would be using the mail() function. (Please correct me if i am wrong with that fact). Thus we again come to the first position, where the mail() is not a matter for sending the email.

PS: as for my knowledge i dont know any other mean of using n exernal relayer within a script without using mail(), please correct me if I am wrong on that

What happens when host2 suddenly stops the mail function after understand it is being spammed?

That would cause an interruption but as i said in the Question "How do you handle the blacklisting of such free hosts?" it can be achieved by some various means which includes having a list of external mail domains or simply having one paid host and providing service to many. The provider can even take a small charge for the server so that there will be no loss for him.
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Yes you are completely wrong in understanding the SMTP. You infact don't need to have any mail feature on your server to send emails using SMTP. Example can be your local PC which even can send emails using smtp. You are using external server to authenticate smtp and send emails.
ManzZup's Avatar, Join Date: May 2009
Skilled contributor
using the smtp with the local machine is of course i do understand, but can you please direct me page which explains about doing the procedure on an external web host without mail()?

i mean as i know there are basically 3 ways to send a mail using php

1) using the default mail() function
2) using an external extension like sendmail as the sender
3) using sockets to connect to the SMTP server (SMTP direct)

but what if ALL these are disabled?

Or is there any other method i have missed?

Last edited by ManzZup; 31Jul2011 at 19:09..
ManzZup's Avatar, Join Date: May 2009
Skilled contributor
however i am about to release the second version of the script with following additions

1: use defualt mail()
2. use direct socket connection
3. use the above method (of using another server)

to send mails
so i would like to know whether there should be any other additional methods?
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Everything is disabled on your server would also allow you to connect to other server if you have internet connectivity allowed on that server and you are allowed outgoing connections on smtp server port.

I am not sure why you would like to have such script when SMTP server can get all done.
ManzZup's Avatar, Join Date: May 2009
Skilled contributor
nope they wont allow ANY type of connection to an external source (even cannot use the header function :S)