Jump to content

prash91

Members
  • Posts

    13
  • Joined

  • Last visited

Posts posted by prash91

  1. Hi I am trying to send email through following php code to may gmail account but it givrs me SMTP Error: Could not connect to SMTP host.

    *******************************************************************************************************************************************************

    <?phpif(isset($_POST['submit'])){
    $message='Full Name: '.$_POST['fullname'].'<br 
    />Subject: '.$_POST['subject'].'<br 
    />Phone: '.$_POST['phone'].'<br 
    />Email: '.$_POST['emailid'].'<br 
    />Comments: '.$_POST['comments'].'';    
    require "phpmailer/class.phpmailer.php"; //include phpmailer 
    class         // Instantiate 
    Class     $mail = new 
    PHPMailer();          // 
    Set up SMTP     
    $mail->IsSMTP();                
    // Sets up a SMTP connection     $mail->SMTPAuth = 
    true;         // Connection with the 
    SMTP does require authorization       
    $mail->SMTPSecure = "ssl";      // Connect using a 
    TLS connection     $mail->Host = 
    "smtp.gmail.com";  //Gmail SMTP server address    
    $mail->Port = 465;  //Gmail SMTP port    
    $mail->Encoding = '7bit';       // 
    Authentication     $mail->Username   = 
    "myemail@gmail.com"; 
    // Your full Gmail address    $mail->Password   
    = "mypassword"; // Your Gmail 
    password         // 
    Compose    $mail->SetFrom($_POST['emailid'], 
    $_POST['fullname']);    
    $mail->AddReplyTo($_POST['emailid'], 
    $_POST['fullname']);    $mail->Subject = "New Contact Form 
    Enquiry";      // Subject (which isn't 
    required)     
    $mail->MsgHTML($message);     // Send 
    To     $mail->AddAddress("myemail@gmail.com", 
    "Recipient Name"); // Where to send it - Recipient    $result 
    = $mail->Send();  // Send!  $message = $result ? 
    'Successfully Sent!' : 'Sending 
    Failed!';      unset($mail);
    }?><html><head>  <title>Contact 
    Form</title></head><body>       <div 
    style="margin: 100px auto 0;width: 
    300px;">   <h3>Contact 
    Form</h3>   <form name="form1" id="form1" action="" 
    method="post">     <fieldset>       
    <input type="text" name="fullname" placeholder="Full Name" 
    />       <br 
    />       <input type="text" 
    name="subject" placeholder="Subject" 
    />       <br 
    />       <input type="text" name="phone" 
    placeholder="Phone" />       <br 
    />       <input type="text" 
    name="emailid" placeholder="Email" />       
    <br />       <textarea rows="4" 
    cols="20" name="comments" 
    placeholder="Comments"></textarea>       
    <br />       <input type="submit" 
    name="submit" value="Send" 
    />     </fieldset>   </form>   <p><?php 
    if(!empty($message)) echo $message; 
    ?></p>  </div>     </body></html>
  2. Hi Fastsol

     

    following is the code, it shows me the message "Thanks for the email" but email dosen't come in my inbox

    <?php
    // Builds an email from given parameters
    function buildEmail($to, $subject, $body, $from, $reply = NULL)
    {
        $headers  = 'MIME-Version: 1.0' . "\r\n";
        $headers .= 'Content-Type: text/html; charset=iso-8859-1' . "\r\n";
        $headers .= 'X-Mailer: PHP/' . phpversion(). "\r\n";
        $headers .= 'From: "'.$from.'" <'.$from.'>' . "\r\n";
        if(!empty($reply)){$headers .= 'Reply-To: '.$reply.'' . "\r\n";}
        
        return (mail($to, $subject, $body, $headers) === TRUE) ? TRUE : FALSE;
    }
    
    if(isset($_POST["submit"]))
    {
    
        $errors = array();
        $name = htmlentities($_POST['name']);
        $email = $_POST['email'];
        $comment = htmlentities($_POST['comment']);
        $emailReg = '/^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/';
    
    
        if(empty($name) || empty($email) || empty($comment))
        {
            $errors[] = 'All fields are required.';
        }
        elseif(!preg_match($emailReg, $email))
        {
            $errors[] = "Not a valid email address";
        }
        
        if(!empty($errors))
        { echo json_encode($errors); }
        else
        {      
            $to = "myemail@gmail.com"; // Edit this to your actual email address you want the emails sent to.
            $from = $email;
            $subject = 'Contact From Submission';
            
            $body  = 'Name: ' .$name . '<br>';
            $body .= 'Email: ' .$email . '<br>';
            $body .= 'Message: ' .$comment . '<br>';
            
            if(buildEmail($to, $subject, $body, $from, $from) === TRUE)
            {
                $return['error'] = false;
                $return['msg'] = "Thanks for your comment";
                echo json_encode($return);
            }
            else
            {
                $return['error'] = true;
                $return['msg'] ="Sorry email not send try again";
                echo json_encode($return);
             }
        }
    }
    
    ?>
  3. Hi Fastsol,

     

    I did following changes to the test.php file but it still dosen't work

     

    <?PHP

    if(isset($_POST["submit"])) {

        $errors = array();
        $name = $_POST['name'];
        $email = $_POST['email'];
        $comment = $_POST['comment'];
        $emailReg = '/^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/ ';


        if(!($name) || !($email) || !($comment)){
            if(!$name){
                $errors[]="Missing Name";
                }
            if(!$email){
                $errors[]="Missing Email";
                }
            if(!$comment){
                $errors[]="Missing Comment";
                }
                $json_response = json_encode($errors);
                     
            }elseif(!preg_match($emailReg,$email)){
                $errors[] = "Not a valid email address";
                $json_response = json_encode($errors);
                
                    
                    
                    
                    $to = "myemail@gmail.com";
                    $from = "demo@yahoo.com";
                    $headers  = 'MIME-Version: 1.0' . '\n';
                    $headers .= 'From:$from' . '\n';
                    $subject = 'Contact From Submission\n';
                    $body = 'Name: ' .$name . '\n';
                    $body .='Email: ' .$email . '\n';
                    $body .='Message: ' .$message . '\n';
                    if(mail($to,$subject,$body,$headers)){
                        $return['error'] = false;
                        //$json_response = json_encode("Thanks for your comment");
                        $return['msg'] ="<p>Thanks for your comment</p>";
                        echo json_encode($return);
                        }else{
                            $return['error'] = false;
                        //$json_response = json_encode("Thanks for your comment");
                        $return['msg'] ="<p>Thanks for your comment</p>";
                        echo json_encode($return);
                            //$json_response = json_encode("Sorry email not send try again");
                            }
                    
                    }
                    echo $json_response;

    }
    ?>
     

  4. Thanks for the message fastsol:

    I have modified the test page code as

     

    <?PHP

    if(isset($_POST["submit"])) {

        $errors = array();
        $name = $_POST['name'];
        $email = $_POST['email'];
        $comment = $_POST['comment'];
        $emailReg = '/^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/ ';

        if(!($name) || !($email) || !($comment)){
            if(!$name){
                $errors[]="Missing Name";
                }
            if(!$email){
                $errors[]="Missing Email";
                }
            if(!$comment){
                $errors[]="Missing Comment";
                }
                $json_response = json_encode($errors);
                     
            }elseif(!preg_match($emailReg,$email)){
                $errors[] = "Not a valid email address";
                $json_response = json_encode($errors);
                
                    
                    $json_response = json_encode("Thanks for your comment");
                    function buildEmail($to, $subject, $body, $from, $reply = NULL)
    {
        $headers  = 'MIME-Version: 1.0' . "\r\n";
        $headers .= 'Content-Type: text/html; charset=iso-8859-1' . "\r\n";
        $headers .= 'X-Mailer: PHP/' . phpversion(). "\r\n";
        $headers .= 'From: "'.$from.'" <'.$from.'>' . "\r\n";
        if(!empty($reply)){$headers .= 'Reply-To: '.$reply.'' . "\r\n";}
        $to = "mymail@gmail.com";
        $subject ="Msg for you";
        return (mail($to, $subject, $body, $headers) === TRUE) ? TRUE : FALSE;
    }
                    }
                    echo $json_response;

    }
    ?>

     

    still dosen't work

  5. Hi I have a following code, validation part and jquery works perfectly in the code but it dosent send the email 

    I have jquery.js file in the head section of html and it work perfectly

     

    contact.php

     
    <div id="emailcontainer">
    
    <div id="ack"> </div>
    
    <div id="emailsend"><img src="images/emailsend.gif"></img><br> <p>We will get back to you soon</p></div>
    
    
    
    <form id="contactform">
    
    <div>
    
    <label for="name">NAME:</label>
    
    <input type="text" name="name" id="name" placeholder="John Doe" />
    
    </div>
    
    <div>
    
    <label for="email">EMAIL:</label>
    
    <input type="text" name="email" id="email" placeholder="JohnDoe@example.com" />
    
    </div>
    
    <div>
    
    <label for="comment">MESSAGE:</label>
    
    <textarea name="comment" rows="10" cols="50" id="comment"></textarea>
    
    </div>
    
    <input type="submit" name="submit" value="SEND" id="submit" />
    
    </form>
    
    </div><!---div emailcontainer end here--->
    
    </div><!---div main end here--->
     
    

    this page does the validation part from php

     

    test.php

     
     
    <?php
    
     if(isset($_POST["submit"])) {
    
    
    
        $errors = array();
    
        $name = $_POST['name'];
    
        $email = $_POST['email'];
    
        $comment = $_POST['comment'];
    
        $to = "reboosttechnologies@gmail.com";
    
        $from = $_POST['email'];
    
        $headers = "From: $from";
    
        $flag = false;
    
        $success = mail($to,$comment,$headers);
    
        $emailReg = '/^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/ ';
    
    
    
        if(!($name) || !($email) || !($comment)){
    
            if(!$name){
    
                $errors[]="Missing Name";
    
                }
    
            if(!$email){
    
                $errors[]="Missing Email";
    
                }
    
            if(!$comment){
    
                $errors[]="Missing Comment";
    
                }
    
                $json_response = json_encode($errors);
    
                     
    
            }elseif(!preg_match($emailReg,$email)){
    
                $errors[] = "Not a valid email address";
    
                $json_response = json_encode($errors);
    
                }elseif($success){
    
                      $flag = true;
    
    
    
                    return $flag;}else{
    
                    
    
                    $json_response = json_encode("Thanks for your comment");
    
                    }
    
                    echo $json_response;
    
    
    
    
    
    }
    
    ?>
    

    this file does the jquery validation without page refresh

    function.js

     
    $(function(){
    
        $("#emailsend").hide();
    
        $("#submit").click(function(event) {
    
       event.preventDefault();
    
            var emailReg = /^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/;
    
            var errors = false;
    
            var name = $('[name=name]').val();
    
            var email = $('[name=email]').val();
    
            var comment = $('[name=comment]').val();
    
            $('.errors').remove();
    
            if($("#name").val() == ""){
    
                $("#name").after("<span class= 'errors'> Missing Name </span>");
    
                errors = true;
    
                }
    
            if($("#email").val() == ""){
    
                $("#email").after("<span class= 'errors'> Missing Email </span>");
    
                errors = true;
    
                }else if(!emailReg.test($('#email').val())){
    
                    $("#email").after("<span class= 'errors'> Not valid Email </span>");
    
                    errors = true;
    
                    }
    
            if($("#comment").val() == ""){
    
                $("#comment").after("<span class= 'errors'> Missing Comment </span>");
    
                errors = true;
    
                }
    
    if(errors == true) {
    
         return false;
    
      } else {
    
         input_data = {
    
            "name"   : name,
    
            "email"  : email,
    
            "comment": comment,
    
            "submit" : true
    
         }
    
        $.ajax({
    
           type: 'post',
    
           url: 'test.php',
    
           data: input_data,
    
           dataType: 'json',
    
           success: function( msg ) {
    
              $("#ack").html(msg);
    
              $("#contactform").delay(500).slideUp(500);
    
              $("#emailsend").show(700);
    
           },
    
           error: function() {
    
              $("#ack").html('ERROR!');
    
           }
    
        });  
    
    }
    
    
    
    
    
                    
    
            
    
            });
    
        });
    
     
     
    
  6. Well, the data what i insert here from form which, is createxmlfile.php and display.php 

    makes new xml file called xmlphp1.xml

    it gives me the results

    for example

    <?xml version="1.0" encoding="utf-8"?>
    <students>
     <student>
      <id>123</id>
      <name>Paul</name>
     </student>
     <student>
      <id>124</id>
      <name>Sandy</name>
     </student>
    </students>

    so I have these data in my xml file if I try inserting same data let say Paul or 123 it should show me the message that the name is already exists.

  7. I have two php file

    createxmlfile.php and display.php

    I am trying to append the text which i insert through display.php file and create a new xmlfile call phpxml1.php

    everything works perfectly, except it also add duplicate date, I need a hint, how can i avoid inserting duplicate data  

     

    <!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>Create Xml File In PHP</title>
    </head>
    <body>
    <p>Please fill following Data</p>
    <Form action="display.php" method="post">
    ID :<input type="text" id="id" name="id" />
    Name : <input type="text" id="name" name="name" />

    <input type="submit" id="submit" value="Submit">
    </Form>
    </body>
    </html>

     

     

    display.php

    <?PHP
    function c_element($e_name,$parent){
     global $xml;
     $node=$xml->createElement($e_name);
     $parent->appendChild($node);
     return $node;
     }
    function c_value($value,$parent){
     global $xml;
     $value = $xml->createTextNode($value);
     $parent->appendChild($value);
     return $value;
     
     }

    ?>

     

    <?PHP
    $s_id = $_POST['id'];
    $s_name = $_POST['name'];

    echo $s_id. '<br>' .$s_name;
    $xml =new DOMDocument("1.0");
    $xml->load("xmlphp1.xml");

    $root=$xml->getElementsByTagName("students")->item(0);
    $student=c_element("student",$root);

    $id=c_element("id", $student);
    c_value("$s_id",$id);

    $name = c_element("name", $student);
    c_value("$s_name",$name);

    //$xml= new DOMDocument("1.0","utf-8");
    //$employee = $xml->createElement("employee");
    //$employee = $xml->appendChild($employee);

    //$empname = $xml->createElement("empname",$name);
    //$empname = $employee->appendChild($empname);

    //$empemail = $xml->createElement("empemail",$email);
    //$price= $employee->appendChild($empemail);

    $xml->FormatOutput=true;
    //$string_value=$xml->saveXML();
    $xml->save("xmlphp1.xml");

    ?>

  8. Hi have following details of my code, I am making user login, if user click on submit button and if the user is valid the form will side with msg "You have logged in successfully " else it will display msg "incorrect username or password" , the msg will get display in DIV message tag and without reloading the page.so i am using ajax with support of jquery...

     


    •  

     

    Posted Today, 07:36 PM

    Hi got following code but dont know why it is not working

     

    database: login

    table name : register1

    3 fields: username, password, email

     

    filename : login.php

     

    < !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[url="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"][color="#0f72da"]http://www.w3.org/TR...ransitional.dtd[/color][/url]">
    < html xmlns="[url="http://www.w3.org/1999/xhtml"][color="#0f72da"]http://www.w3.org/1999/xhtml[/color][/url]">
    < head>
    < meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    < title>PHP Login with jQuery AJAX</title>
    < link rel="stylesheet" type="text/css" href="css/style.css" />
    < script type="text/javascript" src="js/jquery.latest.min.js"></script>
    < script type="text/javascript">
    $(document).ready(function() {
    
    $("#login").click(function() {
    
    var action = $("#form1").attr('action');
    var form_data = {
    username: $("#username").val(),
    password: $("#password").val(),
    is_ajax: 1
    };
    
    $.ajax({
    type: "POST",
    url: action,
    data: form_data,
    success: function(response)
    {
    if(response == 'success')
    $("#form1").slideUp('slow', function() {
    $("#message").html("<p class='success'>You have logged in successfully!</p>");
    });
    else
    $("#message").html("<p class='error'>Invalid username and/or password.</p>");
    }
    });
    
    return false;
    });
    
    });
    < /script>
    < /head>
    < body>
    < p> </p>
    < div id="content">
    <h1>Login Form</h1>
    <form id="form1" name="form1" action="loginpost.php" method="post">
    <p>
    <label for="username">Username: </label>
    <input type="text" name="username" id="username" />
    </p>
    <p>
    <label for="password">Password: </label>
    <input type="password" name="password" id="password" />
    </p>
    <p>
    <input type="submit" id="login" name="login" />
    </p>
    </form>
    <div id="message"></div>
    < /div>
    < /body>
    < /html>
    

     

     

    filename : loginpost

    < ?php
    
    $is_ajax = $_REQUEST['is_ajax'];
    if(isset($is_ajax) && $is_ajax)
    {
    require("conn1db.php");
    $username = $_REQUEST['username'];
    $password = $_REQUEST['password'];
    
    $sql=mysql_query("select * from register1 where username='$username' AND password='$password'");
    if(mysql_num_rows($sql)>0)
    {
    // Register $myusername, $mypassword and redirect to file “login_success.php”
    session_start();
    $_SESSION['username'] = $_POST['username'];
    echo “success”;
    }
    
    }
    
    ?>[
    /code]
    
    
    file name : style.css
    [code]
    body, input {
    font-family: Georgia, "Times New Roman", Times, serif;
    }
    #content {
    background-color: #eee;
    width: 300px;
    margin: 0 auto;
    border: 1px solid #aaa;
    -moz-border-radius: 10px;
    -moz-box-shadow: 0 0 10px #aaa;
    -webkit-border-radius: 10px;
    -webkit-box-shadow: 0 0 10px #aaa;
    padding: 10px;
    }
    #form1 label {
    display: block;
    font-size: 16px;
    line-height: 25px;
    }
    #form1 input[type=text], #form1 input[type=password] {
    padding: 2px;
    font-size: 16px;
    line-height: 20px;
    width: 250px;
    }
    #form1 input[type=submit] {
    font-size: 20px;
    font-weight: bold;
    padding: 5px;
    }
    .success {
    color: #060;
    }
    .error {
    color: red;
    }
    
    

  9. Hi got following code but dont know why it is not working

     

    database: login

    table name : register1

    3 fields: username, password, email

     

    filename : login.php

    <!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>PHP Login with jQuery AJAX</title>

    <link rel="stylesheet" type="text/css" href="css/style.css" />

    <script type="text/javascript" src="js/jquery.latest.min.js"></script>

    <script type="text/javascript">

    $(document).ready(function() {

     

    $("#login").click(function() {

     

    var action = $("#form1").attr('action');

    var form_data = {

    username: $("#username").val(),

    password: $("#password").val(),

    is_ajax: 1

    };

     

    $.ajax({

    type: "POST",

    url: action,

    data: form_data,

    success: function(response)

    {

    if(response == 'success')

    $("#form1").slideUp('slow', function() {

    $("#message").html("<p class='success'>You have logged in successfully!</p>");

    });

    else

    $("#message").html("<p class='error'>Invalid username and/or password.</p>");

    }

    });

     

    return false;

    });

     

    });

    </script>

    </head>

    <body>

    <p> </p>

    <div id="content">

    <h1>Login Form</h1>

    <form id="form1" name="form1" action="loginpost.php" method="post">

    <p>

    <label for="username">Username: </label>

    <input type="text" name="username" id="username" />

    </p>

    <p>

    <label for="password">Password: </label>

    <input type="password" name="password" id="password" />

    </p>

    <p>

    <input type="submit" id="login" name="login" />

    </p>

    </form>

    <div id="message"></div>

    </div>

    </body>

    </html>

     

    filename : loginpost

     

    <?php

     

    $is_ajax = $_REQUEST['is_ajax'];

    if(isset($is_ajax) && $is_ajax)

    {

    require("conn1db.php");

    $username = $_REQUEST['username'];

    $password = $_REQUEST['password'];

     

    $sql=mysql_query("select * from register1 where username='$username' AND password='$password'");

    if(mysql_num_rows($sql)>0)

    {

    // Register $myusername, $mypassword and redirect to file “login_success.php”

    session_start();

    $_SESSION['username'] = $_POST['username'];

    echo “success”;

    }

     

    }

     

    ?>

     

    file name : style.css

     

    body, input {

    font-family: Georgia, "Times New Roman", Times, serif;

    }

    #content {

    background-color: #eee;

    width: 300px;

    margin: 0 auto;

    border: 1px solid #aaa;

    -moz-border-radius: 10px;

    -moz-box-shadow: 0 0 10px #aaa;

    -webkit-border-radius: 10px;

    -webkit-box-shadow: 0 0 10px #aaa;

    padding: 10px;

    }

    #form1 label {

    display: block;

    font-size: 16px;

    line-height: 25px;

    }

    #form1 input[type=text], #form1 input[type=password] {

    padding: 2px;

    font-size: 16px;

    line-height: 20px;

    width: 250px;

    }

    #form1 input[type=submit] {

    font-size: 20px;

    font-weight: bold;

    padding: 5px;

    }

    .success {

    color: #060;

    }

    .error {

    color: red;

    }

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.