tags:

views:

969

answers:

4

How to get user mails in my free gmail inbox through contact us form on my website. I do not use email with my website name . i use free gmail. I tried many script but the all need email account on domain.

+1  A: 

Basically, it involves the PHP mail() function:

<?php 
     mail(yourGmailAddress, object, message); 
?>

As you have already observed, this solution works only if the webserver operates a mail server. This mail server may forbid unknown users. So you need to have an email account on that web/mail server (I believe this is the case). The second step then is to forward mail from your website address to you gmail account. I am 90% certain that it is possible from your gmail configuration. It may also be possible from your website mail configuration. But don't configure both!

mouviciel
A: 

You can also put your email address into "action" attribute of the form element. But that's very unreliable. Like this:

<form method='post' action='mailto:[email protected]?Subject=Hello'>
...
</form>

Users must have email client installed and configured for this to work properly. There are some other drawbacks. You have to do some research to find whether this method is for you or not. http://www.google.com/search?client=opera&amp;rls=en&amp;q=form+action+mailto&amp;sourceid=opera&amp;ie=utf-8&amp;oe=utf-8

presario
+2  A: 

Does this question have something to do with This One?

Well, so you have a form on your site, your users fill it up and you need an email with that data, right?

Simple example:

<form action="sendMail.php" method="post">
    Name: <input type="text" name="name" id="name" /><br />
    Email: <input type="text" name="email" id="email" /><br />
    Text: <textarea name="text"></textarea><br />
    <input type="submit" value="Send" />
</form>

then, the php page wich send the mail:

//php sendThis.php page
<?php
require("class.phpmailer.php");
$name = $_POST['name'];
$email = $_POST['email'];
$text = $name . ', ' . $email . ' has filled the form with the text:<br />' . $_POST['text'];

$from = '[email protected]';
$to = '[email protected]';
$gmailPass = 'your gmail password';

$mail = new PHPMailer();
$mail->IsSMTP();
// enable SMTP authentication
$mail->SMTPAuth = true;
// sets the prefix to the server
$mail->SMTPSecure = "ssl";
// sets GMAIL as the SMTP server
$mail->Host = 'smtp.gmail.com';
// set the SMTP port
$mail->Port = '465';
// GMAIL username
$mail->Username = $from;
// GMAIL password
$mail->Password = $gmailPass;
$mail->From = $from;
$mail->FromName = $from;
$mail->AddReplyTo($from, $from);
$mail->Subject = 'This is a test!';
$mail->Body = $text;
$mail->MsgHTML($text);
$mail->IsHTML(true);
$mail->AddAddress($to, $to);

if(!$mail->Send()){
    echo $mail->ErrorInfo;
}else{
    echo 'sent!';
    $mail->ClearAddresses();
    $mail->ClearAttachments();
}
?>

EDIT: just tested and works fine. Make sure that the 3 files (class.phpmailer.php, class.pop3.php and class.smtp.php) are in the correct include path

DaNieL
when i tried this i got this error Warning: stream_socket_enable_crypto() [streams.crypto]: this stream does not support SSL/crypto in /home/jitu/public_html/mailer/phpMailer/class.smtp.php on line 194
metal-gear-solid
read this too http://www.lizjamieson.co.uk/2008/09/01/contact-form-problems-with-gmail-and-hotmail/
metal-gear-solid
Dont know, probably is a hosting problem (restriction).I just tried on a 10€/year hosting and it works fine.. i edit my answer with the working one.
DaNieL
is here 2 different email address needed:$from = '[email protected]';$to = '[email protected]';
metal-gear-solid
i got this error now Warning: fsockopen() [function.fsockopen]: unable to connect to ssl://smtp.gmail.com:465 (Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP?) in /home/jitu/public_html/mailer/phpMailer/class.smtp.php on line 122SMTP Error: Could not
metal-gear-solid
Yes, there are 2 different email addresses..usually one is the one who receive the email, the others who send it.. in your case, only one is needed.For the fsockopen() problem, the output talk clearly: you have to enable it in your php (apache?) server.
DaNieL
Can we solve SMTP problem through .htaccess. i do not have permission to edit php.ini on hosting.
metal-gear-solid
Mhhh.. im not sure, but i dont think that .htaccess can help you in this issue
DaNieL
A: 

try enabling openssl

uncomment the line: extension=php_openssl.dll

in php.ini

Luis Palomino