0

I am a beginner to PHP,, I just wanted to create a basic registration form to fill in the details and send mail. I have this on a remote server. I am not able to send email. Can someone please help me resolve the issue .

if($conn->query($sql) === TRUE){


    $message =
   'ID: 201701'.$conn->insert_id. '
    Prefix: ' . $prefix . '
    Name: ' . $name . '
    Contact Number: ' . $contactNo . '
    Address: ' . $Address . '
    Email: ' . $email . '
    Job Title: ' . $JobTitle . '
    Organization: ' . $Organization . '
    City: ' . $City . '
    State: ' . $State . '
    Pin Code: ' . $Pincode;     

    mail('info@xyz.com', 'Registration for xyz',$message, $name."<".$email.">"); 

It sends email to info@xyz.com, but it does not send an email to the one given below.

       $email = "yyyy@gmail.com";
       $to = $email;
        $subject = "Confirmation mail";
        $message = "Hello $prefix $name     
        ID: 201701$conn->insert_id
        Prefix:  $prefix 
        Name:  $name 
        Contact Number:  $contactNo 
        Address:  $Address 
        Email:  $email 
        Job Title:  $JobTitle 
        Organization:  $Organization 
        City:  $City 
        State:  $State 
        Pin Code:  $Pincode";

        $from = "xxx@xxx.com" ;
        $headers = "From: XXX 2016<xxx@xxxx.com>";
        $mail = mail($to,$subject,$message,$headers);
    } 
     else {
        echo "Error: " . $sql . "<br>" . $conn->error;
    }

    if($mail)
    {
        echo '<p style="font-size:22px; color:green"><b>Thank You !<br/><br/>You are now Registered.</b></p>';
    }        
    else
    {
    echo '<span style="color:red">Your registration was not successful. Please try again later or send a mail to xxx@xxxx.com</span>';
    }

ps. Dont consider the number of xxx or yyy in the email id, It is just some random mail.

Vignesh
  • 131
  • 2
  • 5
  • 13

1 Answers1

0

mail function use system mail configured client - usually none or configured just by junk (username@localhost, etc). In many cases, mail will be send but it will be rejected by destination server - and you will never know about it. If you can use plugins as "PhpMailer" - you need to set values like in normal mail client and most mails will be delivered. Or any other that provide configurable host and account that will be used for sending mails.

Grzegorz
  • 121
  • 5