0

Hello,

How to make the contact us works?

Contact Us

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", "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">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>

Do I need to install mail server or something on the web server so that this website can send email to the intended address?

4
Contributors
19
Replies
99
Views
3 Years
Discussion Span
Last Post by nauticalmac
Featured Replies
0

Do I need to install mail server or something on the web server

On a shared host mail would normally work. Check your cPanel or ask your host. If you are running on localhost a mail server needs to be setup. I don't think you can relay using yahoo without authenticating.

0

PHP 'mail' command usually uses the servers sendmail command. To use an external smtp server like yahoo you will need to use something like PHPMailer. I have had a lot of trouble trying to set this up in the past with authentication.

0

I shall be doing this soon, that is, procuring a permanent paid host + business email via host.

Q: If I provide a simple contact link/form through my future site, it handled by the host via their servers, I presume? Is this what this thread is addressing? Are there other methods?

Thank you,
Matthew

Edited by mattyd: Grammar

0

This is the setting from the web server.

Phpinfo

SMTP: webmail.indonusa.net.id

We use xampp for the web server. I only wonder why after I input all the data in the contact form and press kirim / submit. I do not receive the email (I already check my email).

0

Your phpinfo says internal windows support for sendmail is enabled.
First run a test script to test if it is working:

<?php
if(mail('your_email_address', 'Test Email Message Subject', 'test message'))    {
    print("Mail returned success");
}   else    {
    print("Mail failed");
}
?>

Then wait and see if your email arrives.

0

Here is the result:

Warning: mail() [function.mail]: "sendmail_from" not set in php.ini or custom "From:" header missing in C:\xampp\xampp\htdocs\sendmail.php on line 4
Mail failed

Sendmail Test

0

It looks as if your setup may require a 'from' header. Try:

<?php
$to      = 'your email address';
$subject = 'Test Sendmail';
$message = 'test message';
$headers = 'From: donotreply@indonusa.net.id' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();
if(mail($to, $subject, $message, $headers))    {
    print("Mail returned success");
}   else    {
    print("Mail failed");
}
?>
0

Sendmail Test

sendmail.php

<?php

    $to = 'davy_yg@yahoo.com';
    $subject = 'Test Sendmail';
    $message = 'test message';
    $headers = 'From: donotreply@indonusa.net.id' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

    if(mail($to, $subject, $message, $headers)) {
    print("Mail returned success");
    } else {
    print("Mail failed");
    }

?>

Warning: mail() [function.mail]: Failed to connect to mailserver at "webmail.indonusa.net.id" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\xampp\xampp\htdocs\sendmail.php on line 11
Mail failed

line 11: if(mail($to, $subject, $message, $headers)) {
0

So you need an SMTP server that can be connected to.
(I'm sorry, previous posts assumed you had a Linux/Unix server which have built in capability). See both of priteas comments above.
1. If your server is a commercial webhosting service, they should be able to provide you with access to a mail server (cost may be involved)
2. If you have an external mail server that does not need authentication you can use that
3. Set this in your php.ini file:
[mail function]
; For Win32 only.
SMTP = your_smtp_server_here
smtp_port = your_smtp_port_here
sendmail_from = your_from_address_here
4. If your selected smtp server requires authentication (commercial ones do of course) then you will not be able to use PHP's internal 'send' command. Instead, use a PHP package that supports authentication like
PHPMailer
Pear Mail (if your server is configured to use PEAR)

mattyd does this answer your related question about commercial service, typically:
Linux/Unix will support PHP internal 'mail' command (limits on volume of emails)

0

Hello,

This is my php.ini settings:

[mail function]
; For Win32 only.
;SMTP = localhost
SMTP = mailman.prima.net.id
smtp_port = 25

; For Win32 only.
sendmail_from = me@example.com

--------------------------

I test sending email to my contact us form and I still do not receive any email in my yahoo email account (davy_yg@yahoo.com).

The contact form looks like this (except that it's in my localhost) - the one that is online has a different php.ini setting.

http://www.indonusa.net.id/contactus.php

0
  1. Does your test script (sendmail.php, above) now work?
  2. You should have an 'action' for your online form
  3. Your online page has <body> tags in a strange place.
0

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", "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">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>
1

So what you have added is setting the smtp user name. According to what I see on this page:
http://email.about.com/od/accessingyahoomail/f/Yahoo_Mail_SMTP_Settings.htm
you will need to handle SSL and provide a password. So I'm repeating this from my message of three weeks ago:
4. If your selected smtp server requires authentication (commercial ones do of course) then you will not be able to use PHP's internal 'send' command. Instead, use a PHP package that supports authentication like
PHPMailer
Pear Mail (if your server is configured to use PEAR)

0

We actually use our own web server - we use xampp (web server) & windows server (OS).

I do not know whether it requires authentication or not.

Before I move it to the web server, I usually test the program on my own computer (localhost).

Is it possible for me to test my sending email program from my localhost? If so, how?

This is the php.ini in my localhost:

[mail function]
; For Win32 only.
;SMTP = localhost
SMTP = plus.smtp.mail.yahoo.com
smtp_port = 465

Edited by davy_yg

0

contactus.php

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

$mail = new PHPMailer();

$mail->IsSMTP();                                      // set mailer to use SMTP
$mail->Host = "smtp1.example.com;smtp2.example.com";  // specify main and backup server
$mail->SMTPAuth = true;     // turn on SMTP authentication
$mail->Username = "jswan";  // SMTP username
$mail->Password = "secret"; // SMTP password

$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";
?>

What is:

$mail->Host = "smtp.mail.yahoo.com";
$mail->Username = "davy_yg@yahoo.com"; // SMTP username
$mail->Password = "******"; // SMTP password

Is that correct?

Then I get this error message on the first view of contactus.php:

Could not access file: /var/tmp/file.tar.gz Could not access file: /tmp/image.jpg SMTP Error: Could not authenticate. Message could not be sent.

Mailer Error: SMTP Error: Could not authenticate.

----------------

note: I test it in my locahost.

Edited by davy_yg

0

First of all go for a simpler test. Don't use html, don't add attachments.
You seem to have an authentication problem. Was this with the items set up in the text below your code?

$mail->Host = "smtp.mail.yahoo.com";
$mail->Username = "davy_yg@yahoo.com"; // SMTP username
$mail->Password = "******"; // SMTP password
Is that correct?

This might help:
http://stackoverflow.com/questions/3477766/phpmailer-smtp-error-could-not-connect-to-smtp-host/5709799#5709799
Also here's a suggestion from yahoo:
http://ph.answers.yahoo.com/question/index?qid=20110926192310AAGxRov

If not, try reposting the question as "PHPMailer wont authenticate yahoo smtp server". You might get some help from someone with more PHPMailer experience than I have.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.