Hello,

I have this code. After adding this php mailer, I wonder why my form won't appears. Only if I comment out the my code between <?php and ?> then my form appears. Also, how to make my form work so that if I fill it in - in my localhost I still will be able to receive it in my yahoo email?

contactus.php

<?php
/*
    // require_once('recaptchalib.php');
    $name = strip_tags(@$_POST['name']);
    $email = str_replace(" ", "", strip_tags(@$_POST['email']));
    $subject = str_replace(" ", "", strip_tags(@$_POST['subject']));
    $message = strip_tags(@$_POST['message']);
    if (@$_POST['submit']) {
    if ($name&&$email&&$subject&&$message) {
    // $privatekey = "6LfjvdcSAAAAAHNcKjYO5DhTNefxYZHYcfhtrvGC";
    // $resp = recaptcha_check_answer($privatekey,
    // $_SERVER["REMOTE_ADDR"],
    // $_POST["recaptcha_challenge_field"],
    // $_POST["recaptcha_response_field"]);
    // if (!$resp->is_valid) {
    //What happens when the CAPTCHA was entered incorrectly
    // echo "The reCAPTCHA wasn't entered correctly.";
    // } else {
    //Your code here to handle a successful verification
    ini_set("SMTP", "plus.smtp.mail.yahoo.com");
    $body = "

    Name: ".$name."
    Email: ".$email."
    Subject: ".$subject."
    Message: ".$message."
    \r\n";
    mail("davy_yg@yahoo.com", "Message from Indonusa Website", $body, "From: ".$email);
    echo "Your message has been sent, we will get back to your shortly.";
    $name = trim("");
    $email = trim("");
    $subject = trim("");
    $message = trim("");
        }    
    }
    else {
    echo "Please fill in <b>all</b> the fields!";
    }
*/
?>

<?php
require("phpmailer_5.1/class.phpmailer.php");

$mail = new PHPMailer();

$mail->IsSMTP();                                      // set mailer to use SMTP
$mail->Host = "smtp.mail.yahoo.com";  // specify main and backup server
$mail->SMTPAuth = true;     // turn on SMTP authentication
$mail->Username = "davy_yg@yahoo.com";  // SMTP username
$mail->Password = "*******"; // SMTP password
$mail->Port='465';

$mail->From = "from@example.com";
$mail->FromName = "Mailer";
$mail->AddAddress("josh@example.net", "Josh Adams");
$mail->AddAddress("ellen@example.com");                  // name is optional
$mail->AddReplyTo("info@example.com", "Information");

$mail->WordWrap = 50;                                 // set word wrap to 50 characters
$mail->AddAttachment("/var/tmp/file.tar.gz");         // add attachments
$mail->AddAttachment("/tmp/image.jpg", "new.jpg");    // optional name
$mail->IsHTML(true);                                  // set email format to HTML

$mail->Subject = "Here is the subject";
$mail->Body    = "This is the HTML message body <b>in bold!</b>";
$mail->AltBody = "This is the body in plain text for non-HTML mail clients";

if(!$mail->Send())
{
   echo "Message could not be sent. <p>";
   echo "Mailer Error: " . $mail->ErrorInfo;
   exit;
}

echo "Message has been sent";
?>


<div id="carticle3">

<div id="inputID">

<form name="contact" action="<?php $_SERVER['PHP_SELF'] ?>" method="POST">
<div id="title" accept-charset="iso-8859-1">Your Message: </div><br><br>
<input type="text" name="name" placeholder="Your name" value=""><br>
<input type="text" name="email" placeholder="Your email" value=""><br>
<input type="text" name="subject" placeholder="subject" value=""><br>
<textarea rows="4" cols="20" placeholder="Message"></textarea><br><br>
<input type="submit" name="submit" value="kirim" class="button">
</form>
</div>

</div>

See this article. It states you can only use Yahoo when you have a business account.

So your form won't appear because the sending of the mail fails, and then exit is called, terminating your script.

ok, what if I use my company email address? do I still need to use PHPMailer?

we have our own server.

do I still need to use PHPMailer?

You only need PHPMailer if you need to authenticate when sending emails. So, it depends upon your mail server settings.

I comment out exit; and I still do not see my form appears.

@davy Are you trying that on another server or your company ?
However you can modify PHPmailer from your server and ensure auth.. Is granted

If you have your Company server then you precisely don't need PHPmailer to send mail.
Since you are having contact form sent to your email you can just use the
Mail() function with extra basic work to get it works. Do you need a sample I can post one here if you need

ok, then I can just comment out the phpmailer.

Should this works?

contactus.php

<html>
<head>

<link href= "css/contact.css" rel="stylesheet" type="text/css" media="screen"> 
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

<script>

$("#inputID").ready(function(){
  $("#inputID input").focus(function(){
    $(this).css("background-color","#fbecc5");
  });
  $("#inputID input").blur(function(){
    $(this).css("background-color","#f5f5f5");
  });

   $("#inputID textarea").focus(function(){
    $(this).css("background-color","#fbecc5");
  });
  $("#inputID textarea").blur(function(){
    $(this).css("background-color","#f5f5f5");
  });
});


</script>
</head>

<?php include('includes/navigation.php'); ?>


<body>

<div id="titlebar"><div id="title"><h2 class="title">Contact Us</h2></title></div>

<div id="stitle">
Contact Us
</div>

<div id="smalltitlebar"><div id="title">Contact Us</div></div>

<div id="googlemap">
<iframe width="700" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.com/maps/ms?msa=0&amp;msid=212050600248541473831.0004de8d18ea9e610fb35&amp;ie=UTF8&amp;ll=-6.20908,106.77029&amp;spn=0,0&amp;t=m&amp;iwloc=0004e60268a255fbe1c79&amp;output=embed"></iframe><br />
</div>


<?php /*
<div id="map"><img src="images/map.jpg"></div> */ ?>

<div id="carticle1">

<div id="title">Ask us anything </div><br>

Please dont hesitate to contact us regarding 
any question about our services<br><br>

We also have extensive amount of frequently 
asked question (FAQ) that you can access from
 our support page<br><br>

Any email requiring support will be answered
 not longer than 24 hours<br><br>

</div>

<?php

    // require_once('recaptchalib.php');
    $name = strip_tags(@$_POST['name']);
    $email = str_replace(" ", "", strip_tags(@$_POST['email']));
    $subject = str_replace(" ", "", strip_tags(@$_POST['subject']));
    $message = strip_tags(@$_POST['message']);
    if (@$_POST['submit']) {
    if ($name&&$email&&$subject&&$message) {
    // $privatekey = "6LfjvdcSAAAAAHNcKjYO5DhTNefxYZHYcfhtrvGC";
    // $resp = recaptcha_check_answer($privatekey,
    // $_SERVER["REMOTE_ADDR"],
    // $_POST["recaptcha_challenge_field"],
    // $_POST["recaptcha_response_field"]);
    // if (!$resp->is_valid) {
    //What happens when the CAPTCHA was entered incorrectly
    // echo "The reCAPTCHA wasn't entered correctly.";
    // } else {
    //Your code here to handle a successful verification
    ini_set("SMTP", "plus.smtp.mail.yahoo.com");
    $body = "

    Name: ".$name."
    Email: ".$email."
    Subject: ".$subject."
    Message: ".$message."
    \r\n";
    mail("davy_yg@yahoo.com", "Message from Indonusa Website", $body, "From: ".$email);
    echo "Your message has been sent, we will get back to your shortly.";
    $name = trim("");
    $email = trim("");
    $subject = trim("");
    $message = trim("");
        }    
    }
    else {
    echo "Please fill in <b>all</b> the fields!";
    }

?>



<div id="carticle3">

<div id="inputID">

<form name="contact" action="<?php $_SERVER['PHP_SELF'] ?>" method="POST">
<div id="title" accept-charset="iso-8859-1">Your Message: </div><br><br>
<input type="text" name="name" placeholder="Your name" value=""><br>
<input type="text" name="email" placeholder="Your email" value=""><br>
<input type="text" name="subject" placeholder="subject" value=""><br>
<textarea rows="4" cols="20" placeholder="Message"></textarea><br><br>
<input type="submit" name="submit" value="kirim" class="button">
</form>
</div>

</div>


<div id="carticle2">


</body>

<?php include('includes/footer.php'); ?>

<br>

</html>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.