Location:Home > Email Service Knowledge > Article content

Submit Form to Auto Send Emails (With Complete Codes)

AotSend Email API Best 24+ Email Marketing Service (Price, Pros&Cons Comparison) What is a Managed Email API, How it Works? Best 25+ Email Marketing Platforms (Compare Authority,Keywords&Traffic)

We have developed a fully functional code file for sending emails through a contact form. To use this file, you will need to obtain the `app_key` and `template_id` from AOTsend. This article is divided into two parts: the first part guides you through the process of acquiring the `app_key` and `template_id` from AOTsend, while the second part includes the complete code for the email-sending functionality. With these instructions, you'll be able to set up and use the email-sending feature efficiently.


How to obtain the `app_key` and `template_id` from AOTsend?

  1. Register for an account on the AOTsend Email API Platform.

  2. Bind your domain and complete domain verification. After verification, it will automatically be submitted for review. Wait for the review to be approved.

  3. Set up an email template. AOTsend offers high-quality, minimalist templates suitable for various uses.

  4. Obtain the app_key and template_id from steps 2 and 3. (If unclear, contact AOTsend support.)

  5. Download the PHP file (source code for automatic email sending via Contact Form).

  6. In the PHP file, replace app_key and template_id on line 31 with your own. Also, specify the email address where you want to receive emails.

  7. Place the PHP file in your website directory and access it via URL.

  8. Submit a test form to ensure emails are received in your specified mailbox. Check your spam folder if using a new domain.


What are the usage scenarios for Submitting Form Sending Emails

Submitting a form to automatically send emails can be useful in various scenarios. Here are some common usage scenarios:

1. Contact Forms: 

   - Purpose: Allow users to reach out to you directly from your website.

   - Usage: When a user submits a contact form, an email is automatically sent to the specified recipient with the form details.

2. Newsletter Sign-ups:

   - Purpose: Capture user interest in receiving newsletters or updates.

   - Usage: When a user subscribes to a newsletter, an email confirmation or welcome message is automatically sent to them.

3. Order Confirmations:

   - Purpose: Confirm purchase or order details.

   - Usage: After a user completes a purchase or order, an automatic email is sent to confirm the transaction and provide details.

4. Support Requests:

   - Purpose: Manage customer support inquiries.

Submit Form to Auto Send Emails (With Complete Codes)

   - Usage: When a user submits a support request or ticket, an email is automatically sent to acknowledge receipt and provide follow-up information.

5. Feedback Forms:

   - Purpose: Gather user feedback or survey responses.

   - Usage: When a user submits feedback or survey responses, an email is automatically sent to confirm receipt or thank them for their input.

6. Event Registrations:

   - Purpose: Manage event sign-ups and confirmations.

   - Usage: After a user registers for an event, an automatic email is sent to confirm their registration and provide event details.

7. Appointment Bookings:

   - Purpose: Schedule and confirm appointments.

   - Usage: When a user books an appointment, an automatic email is sent to confirm the booking and provide details.

8. Application Submissions:

   - Purpose: Handle job applications or other submissions.

   - Usage: After a user submits a job application or similar form, an automatic email is sent to acknowledge receipt and provide next steps.

9. Password Reset Requests:

   - Purpose: Facilitate password recovery.

   - Usage: When a user requests a password reset, an email is automatically sent with instructions for resetting their password.


These scenarios demonstrate how automatically sending emails upon form submission can streamline communication and improve user experience across various applications.


.

.



🔔🔔🔔

【AOTsend Email API】:AOTsend is a Managed Email Service for sending transactional emails. Support Email Types: reminders, authentication, confirmations, notifications, verification codes, invoices, password resets, account activations, billing statements, two-factor authentication (2FA), and one-time passwords (OTP) emails, etc. $0.28 per 1000 Emails. 99% Delivery, 98% Inbox Rate.


You might be interested in:
Why did we start the AOTsend project, Brand Story?
What is a Managed Email API, How it Works?
Best 25+ Email Marketing Platforms (Authority,Keywords&Traffic Comparison)
Best 24+ Email Marketing Service (Price, Pros&Cons Comparison)
Email APIs vs SMTP: How they Works, Any Difference?

🔔🔔🔔


Complete code for auto sending emails via contact form.

The complete code can be find on Github: Submit Contact Form Auto Sending Emails (PHP Version)

    <?php
    if(!empty($_POST['is_post']) && $_POST['is_post']==1){
        $url = "https://www.aotsend.com/index/api/send_email";
        $name = $_POST['name'];
        $email = $_POST['email'];
        $subject = $_POST['subject'];
        $message = $_POST['message'];
        if(empty($name)){
            echo json_encode(['message'=>'Please Enter Your Name','code' => 40001]);
            exit;
        }
        if(empty($email)){
            echo json_encode(['message'=>'Please Enter Email address','code' => 40002]);
            exit;
        }
        if(empty($subject)){
            echo json_encode(['message'=>'Please Enter Subject','code' => 40003]);
            exit;
        }
        if(empty($message)){
            echo json_encode(['message'=>'Please Enter Message','code' => 40004]);
            exit;
        }
        $time = date('Y-m-d H:i:s',time());
    
        $str = '{"username":"'.$name.'","contactemail":"'.$email.'","subject":"'.$subject.'","content":"'.$message.'","time":"'.$time.'"}';
    
        //app_key (Register AOTsend to Obtain)
        //to (Generally Enter Your Email Address)
        //template_id (Email Template ID in AOTsend)
        $data = ['app_key'=>'cf6d0114ee5cd1e4800000005c20ac793', 'to'=>'[email protected]', 'template_id'=>'E_1000000004408', 'data'=>$str];
    
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
        if (!empty($data)){
            curl_setopt($curl, CURLOPT_POST, 1);
            curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
        }
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $output = curl_exec($curl);
        curl_close($curl);
        echo $output;
        exit;
    }
    ?>
    <style type="text/css">
    html, body {
      background: #f1f1f1;
      font-family: 'Merriweather', sans-serif;
      padding: 1em;
    }
    
    h1 {
       text-align: center;
       color: #565656;
       @include text-shadow(1px 1px 0 rgba(white, 1));
    }
    p{
      text-align: center;
    }
    form {
       max-width: 600px;
       text-align: center;
       margin: 20px auto;
      
      input, textarea {
         border:0; outline:0;
         padding: 1em;
         @include border-radius(8px);
         display: block;
         width: 100%;
         margin-top: 1em;
         font-family: 'Merriweather', sans-serif;
         @include box-shadow(0 1px 1px rgba(black, 0.1));
         resize: none;
        
        &:focus {
           @include box-shadow(0 0px 2px rgba($red, 1)!important);
        }
      }
      
      #input-submit {
         color: white; 
         background-color: #ff5151;
         cursor: pointer;
         margin-top:20px;
        
        &:hover {
           @include box-shadow(0 1px 1px 1px rgba(#aaa, 0.6)); 
        }
      }
      
      textarea {
          height: 156px;
      }
    }
    
    
    .half {
      float: left;
      width: 48%;
      margin-bottom: 1em;
    }
    
    .right { width: 50%; }
    
    .left {
         margin-right: 2%; 
    }
    
    
    @media (max-width: 480px) {
      .half {
         width: 100%; 
         float: none;
         margin-bottom: 0; 
      }
    }
    
    
    /* Clearfix */
    .cf:before,
    .cf:after {
        content: " "; /* 1 */
        display: table; /* 2 */
    }
    
    .cf:after {
        clear: both;
    }
    </style>
    <h1>Contact Form</h1>
    <p>Supported by AOTsend Email API</p>
    <form class="cf">
      <div class="half left cf">
        <input type="text" id="input-name" placeholder="Name">
        <input type="email" id="input-email" placeholder="Email address">
        <input type="text" id="input-subject" placeholder="Subject">
      </div>
      <div class="half right cf">
        <textarea name="message" type="text" id="input-message" placeholder="Message"></textarea>
      </div>  
      <input type="submit" value="Submit" id="input-submit">
    </form>
    
    <script>
      function submitForm() {
        // Prevent the default form submission behavior
        event.preventDefault();
    
        // Assuming your form data is in the following object
        var formData = {
          is_post: 1,
          name: document.getElementById('input-name').value,
          email: document.getElementById('input-email').value,
          subject: document.getElementById('input-subject').value,
          message: document.getElementById('input-message').value
        };
    
        // Convert the form data into a query string
        var queryString = Object.keys(formData).map(key => encodeURIComponent(key) + '=' + encodeURIComponent(formData[key])).join('&');
    
        // Initialize the XMLHttpRequest object
        var xhr = new XMLHttpRequest();
    
        // Set the request type, URL, and asynchronous flag
        xhr.open('POST', '', true);
    
        // Set the request headers (if needed)
        xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    
        // Set the response handling function
        xhr.onreadystatechange = function () {
          if (xhr.readyState === 4 && xhr.status === 200) {
            // Request completed successfully
            var obj = JSON.parse(xhr.responseText);
            if(obj.code==200){
              //Call was successful
              alert("Submission successful; email has been sent!")
            }else{
              alert(obj.message)
            }
          }
        };
        // Send the request
        xhr.send(queryString);
      }
      document.getElementById('input-submit').addEventListener('click', submitForm);
    </script>


AotSend Email API Best 24+ Email Marketing Service (Price, Pros&Cons Comparison) What is a Managed Email API, How it Works? Best 25+ Email Marketing Platforms (Compare Authority,Keywords&Traffic)

    Scan the QR code to access on your mobile device.

    Copyright notice: This article is published by AotSend. Reproduction requires attribution.

    Article Link:https://www.mailwot.com/p78.html