Current location: Hot Scripts Forums » Other Discussions » Other Topics » phpMailer with ajax


phpMailer with ajax

Reply
  #1 (permalink)  
Old 10-05-09, 02:32 PM
raizel's Avatar
raizel raizel is offline
Newbie Coder
 
Join Date: Feb 2009
Location: India
Posts: 37
Thanks: 3
Thanked 0 Times in 0 Posts
Exclamation phpMailer with ajax

hi,

I am struck between ajax and phpMailer.I have a contact form the script of which is saved in contact-us.php
PHP Code:


<?php include("include/header.php");?>
<script language="javascript">

function createRequestObject() {
    var ro;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
        ro = new ActiveXObject("Microsoft.XMLHTTP");
    }else{
        ro = new XMLHttpRequest();
    }
    return ro;
}

var http = createRequestObject();

function sendemail() {
    var name = document.contactform.name.value;
    var email = document.contactform.email.value;
    var company = document.contactform.company.value;
    var phone = document.contactform.phone.value;
    var inquire = document.contactform.inquire.value;
    var msg = document.contactform.comments.value;
    var subject = "Website Contact Enquiry";
    document.contactform.send.disabled=true;
    document.contactform.send.value='Sending....';

    http.open('get', 'sendit.php?name='+name+'&email='+email+'&company='+company+'&phone='+phone+'&inquire='+inquire+'&msg='+msg+'&subject='+subject+'&action=send');
    http.onreadystatechange = handleResponse;
    http.send(null);
}

function handleResponse() {
    if(http.readyState == 4){
        var response = http.responseText;
        var update = new Array();

        if(response.indexOf('|' != -1)) {
            update = response.split('|');
            document.getElementById(update[0]).innerHTML = update[1];
        
        }
    }
}

</script>
 
<div id="contentPages">
                <h1>Get in Touch with Us</h1>
                <p>
Please complete the form below if you'd like more information on our Products and services.We also welcome any other questions or comments that you may have.
</p>
<p>
Please Note: Current ActivaSpace customers should contact us through the ActivaSpace <a href="https://activaspace.ibizpanel.net/cgi-bin/login.cgi">Customer Portal</a>, where support requests will be routed to the appropriate Level 2 hardware technician or Level 3 software engineer. Thank you!
</p>
               
                <div class="contactInfo">
                    <ul class="phoneRight">
                        <li class="title">Support</li>
                    <li><span >Online</span><span> Mon to Sat 10am to 6PM</span></li>
                        <li><span>Offline (Ticket)</span><span> 24x7</span></li>
                        <li><span>E-mail</span><span > ticket@activsapce.com</span></li>
                      </ul>
                    <ul class="address">
                        <li class="title">Sales</li>
                    <li>Monday to Saturday</li>
                        <li>Time: 10am to 6pm EST</li>
                        <li>Email: billing@activaspace.com</li>
                      </ul>
                </div><!-- END Contact Info -->
<div id='txtShow'>
 
<form name="contactform"  class="contactForm"><INPUT NAME="op" TYPE="hidden" VALUE="send">
                    <fieldset>
                          <label for="name">Name:<span class="required">*</span></label>
                            <input id="name" type="text" name="name" value="" /><br />
                          <label for="email">Email Address:<span class="required">*</span></label>
                            <input id="email" type="text" name="email" value="" /><br />

                <label for="company">Company:<span class="required">*</span></label>
                            <input id="company" type="text" name="company" value="" /><br />

                         
                         <label for="phone">Phone Number:</label>
                            <input id="phone" type="text" name="phone" value="" /><br />
                        <label for="inquire">Inquiring About:<span class="required">*</span></label>
                            <select id="inquire" name="inquire">
                                  <option value="none">select an option</option>
                                  <option value="sales" selected>sales</option>

                                  <option value="support" >support</option >
                                  <option value="service" >service</option>
                                  <option value="returned product" >returned products</option>
                            </select><br />
                          <label for="comments">Comments:<span class="required">*</span></label>
                            <textarea name="comments" id="comments"><? echo $comments ?></textarea><br />

                               
                <div style="padding-left:1px;"><input name="send" type="button" value="Send Message" onclick="sendemail();" id="submitbutton"></div>
                           
                    </fieldset>
                    <div class="requiredNote"><p>All fields marked with an <span class="required">*</span> are required</p></div>
                  </form>
</div>

            </div><!-- END Sub Pages -->
            
             <?php include("include/left_nav.html");?>
           
          <?php include("include/footer.php");?>
the other one which is saved in sendit.php
PHP Code:

<?php

if(!isset($_GET['action']))
{
die(
"You must not access this page directly!"); //Just to stop people from visiting contact.php normally
}
$name trim($_GET['name']); //The senders name
$email trim($_GET['email']); //The senders email address
$company trim($_GET['company']); //The senders company address
$phone trim($_GET['phone']); //The senders phone
$inquire trim($_GET['inquire']); //The senders inquiry
$message trim($_GET['msg']); //The senders message
// Enter path to class.phpmailer.php if this form is not in the same folder as it.
require("class.phpmailer.php");
$mailer = new PHPMailer();
$mailer->IsSMTP();
$mailer->Host 'ssl://smtp.gmail.com:465';
$mailer->SMTPAuth TRUE;
$mailer->Username ' ';  // Change this to your gmail address
$mailer->Password ' ';  // Change this to your gmail password
$mailer->From 'xxxxxxxxx@gmail.com';  // This HAS TO be your gmail address or it won't work!
$mailer->FromName 'From Me'// This is the from name in the email, you can put anything you like here
$mailer->Body "Name: ".$name.''."Email ".$email.''."Company: ".$company.''."Phone: ".$phone.''."Inquire: ".$inquire.''."Message: ".$message;
$mailer->Subject $subject;
$mailer->AddAddress("xyz@xyz.com");


if (!
trim($name)) { 
  echo 
"<font color='red'><p>Please enter your Name</p></p>.</font>"
}
elseif (!
eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,6}$"$email)) {

  echo 
"<font color='red'><p>It appears you entered an invalid email address</p>.</font>";

}

elseif (!
trim($message)) {

  echo 
"<font color='red'><p>Please go back and type a Message</p>.</font>";



 elseif (!
trim($email)) {

  echo 
"<font color='red'><p>Please go back and enter an Email</p>.</font>";

}
else {
echo 
'contactarea|Thank you '.$name.', your email has been sent.'//now lets update the "contactarea" div on the contact.html page. The contactarea| tell's the javascript which div to update
}
  if(!
$mailer->Send())
   {
      echo 
"Message was not sent<br/ >";
      echo 
"Mailer Error: " $mailer->ErrorInfo;
   }

 
?>
the output is nil,As I am new to php though tried but cannot figure it out where the mistake is,kindly help me out.

Thanks,

Raizel

Last edited by Nico; 06-15-10 at 05:30 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] AJAX Cache DAL JavaScript 7 06-17-08 10:15 AM
AJAX problem with php dynamic url scott2500uk PHP 3 10-28-06 11:33 AM
Want to bring your website up to date? Convert to AJAX! Anastas Job Offers & Assistance 7 08-22-06 05:13 AM
Need AJAX Engineer for Full time open source work in Seattle Ryan_Singer Job Offers & Assistance 0 02-15-06 05:57 PM
need Java script ( Ajax) Calendar, tree, grid curtisannev Job Offers & Assistance 1 10-30-05 09:59 PM


All times are GMT -5. The time now is 12:47 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.