Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #8539 > unrolled thread

Mail() function

Started byRita Ferreira <ritaferreira83@gmail.com>
First post2013-03-06 06:46 -0800
Last post2013-03-06 19:14 +0100
Articles 4 — 4 participants

Back to article view | Back to comp.lang.php


Contents

  Mail() function Rita Ferreira <ritaferreira83@gmail.com> - 2013-03-06 06:46 -0800
    Re: Mail() function Salvatore <sal@yojimbo.hack.invalid> - 2013-03-06 15:26 +0000
    Re: Mail() function The Natural Philosopher <tnp@invalid.invalid> - 2013-03-06 15:37 +0000
    Re: Mail() function Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-03-06 19:14 +0100

#8539 — Mail() function

FromRita Ferreira <ritaferreira83@gmail.com>
Date2013-03-06 06:46 -0800
SubjectMail() function
Message-ID<e58d9e16-5e3e-4258-8a66-2c34c1aa3814@googlegroups.com>
Hi,
I'm new at PHP and I'm facing problems with the mail() function.
I'm trying to send an email from a form and to do it I'm using mail() function but gmail assume it like spam.

I have read lots of similar problems in internet but I couldn't find a solution.


<?php

  if (isset($_REQUEST['email']))
  {
  $nome = $_REQUEST['nome'] ;
  $telefone = $_REQUEST['telefone'] ;
  $email = $_REQUEST['email'] ;
  $message = $_REQUEST['mensagem'] ;
  $header .= "Reply-To:".$nome." <".$email.">\r\n"; 
  $header .= "Return-Path: ".$nome." <".$email.">\r\n"; 
  $header .= "From: ".$nome." <".$email.">\r\n"; 
  $header .= "Organization: MyOrganization\r\n"; 
  $header .= "Content-Type: text/plain\r\n"; 
 
    mail("XXXXX@gmail.com", "My message", $message, $header); 

    header ('Location:index_teste.php?area=contactenos');
  }


Can you please help me trying to find what I do have wrong here?
Any help will be welcome.
Thanks.

[toc] | [next] | [standalone]


#8540

FromSalvatore <sal@yojimbo.hack.invalid>
Date2013-03-06 15:26 +0000
Message-ID<kh7n7r$2b27$1@yojimbo.hack>
In reply to#8539
On 2013-03-06, Rita Ferreira <ritaferreira83@gmail.com> wrote:
> Hi,
> I'm new at PHP and I'm facing problems with the mail() function.
> I'm trying to send an email from a form and to do it I'm using mail() function but gmail assume it like spam.

If Google Mail believes that it's spam, that isn't a problem with the
PHP code. However, you should make sure that there is a space after the
first colon (":") in the headers.

-- 
Blah blah bleh...
GCS/CM d(-)@>-- s+:- !a C++$ UBL++++$ L+$ W+++$ w M++ Y++ b++

[toc] | [prev] | [next] | [standalone]


#8541

FromThe Natural Philosopher <tnp@invalid.invalid>
Date2013-03-06 15:37 +0000
Message-ID<kh7nsf$nuv$1@news.albasani.net>
In reply to#8539
On 06/03/13 14:46, Rita Ferreira wrote:
> Hi,
> I'm new at PHP and I'm facing problems with the mail() function.
> I'm trying to send an email from a form and to do it I'm using mail() function but gmail assume it like spam.
>
> I have read lots of similar problems in internet but I couldn't find a solution.
>
>
> <?php
>
>    if (isset($_REQUEST['email']))
>    {
>    $nome = $_REQUEST['nome'] ;
>    $telefone = $_REQUEST['telefone'] ;
>    $email = $_REQUEST['email'] ;
>    $message = $_REQUEST['mensagem'] ;
>    $header .= "Reply-To:".$nome." <".$email.">\r\n";
>    $header .= "Return-Path: ".$nome." <".$email.">\r\n";
>    $header .= "From: ".$nome." <".$email.">\r\n";
>    $header .= "Organization: MyOrganization\r\n";
>    $header .= "Content-Type: text/plain\r\n";
>
>      mail("XXXXX@gmail.com", "My message", $message, $header);
>
>      header ('Location:index_teste.php?area=contactenos');
>    }
>
>
> Can you please help me trying to find what I do have wrong here?
> Any help will be welcome.
> Thanks.
>

the line the works for me is this

mail($email, $subject, $message, $headers, "-f ".$return_path );

Note the -f argument to set a valid sender address, otherwise mail 
relays can and will reject the message.

In my case $return_path contains 'webmaster@mysite.com' etc etc.

Also depending on the server you are posting from, the mail relay 
subsystem may not be set up correctly.

-- 
Ineptocracy

(in-ep-toc’-ra-cy) – a system of government where the least capable to 
lead are elected by the least capable of producing, and where the 
members of society least likely to sustain themselves or succeed, are 
rewarded with goods and services paid for by the confiscated wealth of a 
diminishing number of producers.

[toc] | [prev] | [next] | [standalone]


#8544

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2013-03-06 19:14 +0100
Message-ID<5093423.8btqtlOBGm@PointedEars.de>
In reply to#8539
Rita Ferreira wrote:

> I'm new at PHP and I'm facing problems with the mail() function.
> I'm trying to send an email from a form and to do it I'm using mail()
> function but gmail assume it like spam.
> 
> I have read lots of similar problems in internet but I couldn't find a
> solution.
> 
> <?php
> 
>   if (isset($_REQUEST['email']))
>   {
>   $nome = $_REQUEST['nome'] ;
>   $telefone = $_REQUEST['telefone'] ;
>   $email = $_REQUEST['email'] ;
>   $message = $_REQUEST['mensagem'] ;

This is just wrong.  Sanitize your input, and in this case accept data via 
$_POST only, so that it is harder to use your script for spamming via URIs.

>   $header .= "Reply-To:".$nome." <".$email.">\r\n";

The first string assignment to a variable should be

  $header = …

because the variable is undefined before the assignment and

  $header .= …

is equivalent to

  $header = $header . …

>   $header .= "Return-Path: ".$nome." <".$email.">\r\n";

Trace fields like that are to be set by the Message Transfer Agent (MTA), 
not the Mail User Agent (MUA; here: mail()).  Sending messages with 
additional trace fields could reasonably be regarded an attempt at spamming, 
because it could be construed as an attempt to conceal the true origin of 
the message, and the path it took when transported through the network(s).

If you inspect your e-mails (Ctrl+U etc.), you will find that “Return-Path” 
and “Received” header fields are never contained in the messages that you 
sent, only in those you received.  (“Received” header fields show the path 
of the message in descending order; *they* are the best clue as to where the 
spam originated, _not_ the “From” header field which can be easily forged.)

<http://tools.ietf.org/html/rfc5322#section-3.6.7> p.

You are sending a “Reply-To” field already, so there is no need for a bogus 
“Return-Path” field.

I strongly suggest that you do not use the mail() function unless you know 
what you are doing; use existing mail classes instead, like PHPMailer:

<https://code.google.com/a/apache-extras.org/p/phpmailer/>

In addition, you may have been sending e-mail from a suspicious or 
blacklisted host.  Check to see if the IP address of the Internet gateway of 
your PHP host, or the IP address range it is in, is blacklisted.  You SHOULD 
NOT send e-mails with PHP from a computer in your home network; since its 
Internet gateway will likely have been assigned a dynamic IP address by the 
ISP, the message will most certainly be regarded spam because of that.  Get 
external PHP Web hosting instead and try again from there.


PointedEars
-- 
var bugRiddenCrashPronePieceOfJunk = (
    navigator.userAgent.indexOf('MSIE 5') != -1
    && navigator.userAgent.indexOf('Mac') != -1
)  // Plone, register_function.js:16

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.php


csiph-web