send email from javascript php not working

Discussion in 'Email' started by Zorglub, Mar 8, 2015.

  1. Hi,

    I am trying to send an email from javascript with php.
    But it looks like it is not working.
    I narrowed it down to the php mail function.

    After reading that link https://support.Winhost.com/kb/a826/how-to-send-email-from-a-php-application.aspx I tried to apply the smtp settings to make it work.
    But so far to no avail.

    This is the php code I have (with your sample integrated)

    PHP:
    <?php

    include dirname(dirname(__FILE__)).'/mail.php';

    error_reporting (E_ALL E_NOTICE);

    $post = (!empty($_POST)) ? true false;

    if(
    $post)
    {
    include 
    'email_validation.php';

    $name stripslashes($_POST['name']);
    $email trim($_POST['email']);

    $error '';

    // Check name

    if(!$name)
    {
    $error .= 'Please enter your name.<br />';
    }

    // Check email

    if(!$email)
    {
    $error .= 'Please enter an e-mail address.<br />';
    }

    if(
    $email && !ValidateEmail($email))
    {
    $error .= 'Please enter a valid e-mail address.<br />';
    }

    if(!
    $error)
    {
    $from "Sender <[email protected]>"
    $to "Recipient <[email protected]>"
    $subject "This is a test email sent via php"
    $body "This is a test email"
    $host "mail.myDomainname.com"
    $username "[email protected]"
    $password "myPassword"
    $headers = array ('From' => $from
      
    'To' => $to
      
    'Subject' => $subject); 
    $smtp Mail::factory('smtp'
      array (
    'host' => $host
      
    'auth' => true
      
    'username' => $username
      
    'password' => $password)); 
    $mail $smtp->send($to$headers$body);

    $mail mail(CONTACT_FORM$subject"From: ".$name." <".$email.">\r\n");
    if(
    $mail)
    {
    echo 
    'OK';
    }
    else
    {
    echo 
    'KO';
    }

    }
    else
    {
    echo 
    '<div class="notification_error">'.$error.'</div>';
    }

    }
    ?>
    Now, if I remove your smtp code, The code goes through, but returns 'KO'.
    If I put your code, nothing happens. at all.
    It's like the function explode silently.

    What am I doing wrong?
    Do I need to modify something else somewhere to make this work ?
     
    Last edited by a moderator: Oct 14, 2015
  2. ComputerMan

    ComputerMan Winhost Staff

    Try changing to PHP version to 5.3 within your control panel. Then recycle your application pool within the control panel and wait 2 minutes. Then try to send the email message again.
     
  3. Hi,

    I just did that.

    Now I get the following error to show:

    Code:
    Fatal error: Class 'Mail' not found in E:\web\whoshaco\contact_form\contact_process.php on line 52
    I do not know PHP.
    So is there some library I have to include or something ?
    or config file?
     
  4. ComputerMan

    ComputerMan Winhost Staff

    I didn't get an error message on my end. Can you try it again?

    Our server takes some time to change versions from one PHP version to another.
     
  5. I found it.

    I had this
    Code:
    include dirname(dirname(__FILE__)).'/mail.php';
    instead of that
    Code:
    require_once "Mail.php";
    So now it says that the mail has been sent.
    But I am not receiving it on the other side.

    Do I still need to do
    Code:
    $mail = mail(CONTACT_FORM, $subject, "From: ".$name." <".$email.">\r\n");
    
    in addition to the smtp ?
     
  6. Actually I tried to send an email from my own private address to the receiver, and it looks like it is not coming in either.
    I am not sure what to do now....

    Edit:
    nvm, I got the email from my private account.
    But still nothing from the php script.:(
     
    Last edited: Mar 9, 2015
  7. ComputerMan

    ComputerMan Winhost Staff

    Contact us via our support portal here: http://support.Winhost.com

    Provide us with the following on the ticket you opened.

    1. Provide us with the link to this forum post. This will let us know we tried to trouble shoot this with you here.

    2. Provide us with examples on how to send the email message from your site so we can recreate the issue on our end.

    3. Provide us with the From Email address that was used to send the email message.

    5. To what email address was the email message sent to?

    6. Time and date that the email message was sent.

    We will then be able to check the SMTP logs on our mail server to see if it could be a email issue or a PHP sending email issue.
     
    Last edited by a moderator: Oct 14, 2015
    Michael likes this.

Share This Page