I'm working through a contact form from Sinatra Jump Start and trying to figure out why the "From" is always the same gmail account I'm using as the :user_name. I have an Heroku version and it's also always the same :from. My goal is to have the little contact form where there is Name, Email and Message send to the receiving email and the "From" would be the sender's Name and Email.
I thought maybe this is because of local version, but it's the same result on Heroku. The setting for :user_name ends up as the "From" I'm doing something wrong, any ideas?
Is the :from => params[:name] + "<" + params[:email] + ">" that's no longer correct, the book I'm working from isn't too old.
Here's what my contact.slim form looks like:
p You can contact me by filling in the form below:
form class="contact" action="/contact" method="POST"
p
label for="name" Name:
input type="text" name="name"
p
label for="email" Email:
input type="text" name="email"
p
label for="message" Your Message:
textarea name="message"
input type="submit" value="Send Message"
Here's my send_message:
def send_message
Pony.mail(
# this always comes back as the same gmail.account I'm using for the :user_name
:from => params[:name] + "<" + params[:email] + ">",
:to => 'mygmail#gmail.com',
:subject => params[:name] + " from #{params[:email]} has contacted you ",
:body => params[:message],
:via => :smtp,
:via_options => {
:address => 'smtp.gmail.com',
:port => '587',
:enable_starttls_auto => true,
:user_name => 'mygmail#gmail.com',
:password => 'mypassword',
:authentication => 'plain',
:domain => 'localhost.localdomain'
})
end
And my post route handler from my main.rb
post '/contact' do
send_message
flash[:notice] = "Thank you for your message. We'll be in touch soon."
redirect to("/")
end
Then when I tried on Heroku for I have this in the main.rb:
configure :development do
# for the local MySQL db
DataMapper.setup(:default, 'mysql://root:admin#localhost/sinatra_jumpstart')
set :email_address => 'smtp.gmail.com',
:email_user_name => 'mygmail#gmail.com',
:email_password => 'mypassword',
:email_domain => 'localhost.localdomain'
end
configure :production do
# for Heroku
DataMapper.setup(:default, ENV[ 'DATABASE_URL' ])
set :email_address => 'smtp.sendgrid.net',
:email_user_name => ENV['SENDGRID_USERNAME'],
:email_password => ENV['SENDGRID_PASSWORD'],
:email_domain => 'heroku.com'
end
Update: It seems like if my goal is to be able to reply-to, there's a :reply_to option that I can pass the params[:email] to, but that still leaves me wondering why the 'From' show the name (coming from params[:name]) correctly, but ignores the params[:email] for the 'From' email address and instead shows my :user_name email from the :via_options instead.
This answer came from a sitepoint discussion.
You are sending the form from your webpage and so the sender is yourself.
If you were opening the senders email software ( using the html mail function? ) and the user was sending from that it would have their email address.
This happens a lot in forums when the user gets an email from another user and uses "reply". The email is then sent to the forum admin. There is usually a note on the message saying something like "Do not reply to this message but do so in the forum messaging section".
Related
I am using the BeautyMail package to send an email, which is sent successfully via stmp.gmail.com. I found out that the content of emails.welcome (welcome.blade.php) is not included, the email delivered is empty.
Below is my code;
$data = array(
'LastName' => 'ABC Widget', // Company name
'senderName' => 'ABC Widget', // Company name
'reminder' => 'You’re receiving this because you’re an awesome ABC Widgets customer or subscribed via our site',
'unsubscribe' => null,
'address' => '87 Street Avenue, California, USA',
'twitter' => 'http://www.facebook.com/abcwidgets',
'facebook' => 'http://twitter.com/abcwidgets',
'flickr' => 'http://www.flickr.com/photos/abcwidgets'
);
Mail::send('emails.welcome', $data, function($message)
{
$message->from( 'johnny#gmail.com', 'John Doe' );
$message->to('Suzanne#yahoo.com', 'Suzanne Doe')->subject('Testing Messages');
});
VIEW
#extends('beautymail::templates.widgets')
#section('content')
#include('beautymail::templates.widgets.articleStart')
<h4 class="secondary"><strong>Hello World</strong></h4>
<p>This is a test</p>
#include('beautymail::templates.widgets.articleEnd')
#include('beautymail::templates.widgets.newfeatureStart')
<h4 class="secondary"><strong>Hello World again</strong></h4>
<p>This is another test</p>
#include('beautymail::templates.widgets.newfeatureEnd')
#stop
No error was reported. What I am doing wrong?
Trying removing the BeautyMail package and testing it. When I tried using the BeautyMail package, I had a similar problem.
Beautymail have Ruby dependencies. I do think one of them fails which renders the empty email.
This issue has more details:
https://github.com/Snowfire/Beautymail/issues/2
Remove the inliner found in the service provider to remove the ruby dep.
So I have a script that I'm trying to get VERP running correctly on. It's using MIME::Lite and postfix as the mail server. Here is the code:
use strict;
use MIME::Lite;
use LWP::Simple;
use Mail::Verp;
my $email = 'someuser#somesite.com';
Mail::Verp->separator('+');
my $verp_email = Mail::Verp->encode('root#somesite.net', $email);
my $content = '<html><body>Hi!</body></html>';
my $msg = MIME::Lite->new(
Subject => 'Hi',
From => 'root#somesite.net',
To => $email,
'Return-Path' => $verp_email,
Type => 'text/html',
Data => $content
);
$msg->send('smtp', 'XXX.XXX.XXX.XXX');
When the message is bounced postfix isn't routing it to the root#somesite.net email inbox. How do I route the message so that the sender of the bounce is the $verp_email value?
I'm trying to create a log of all bounced emails with the email addresses included so that it can then be sent to a file or a database.
If anyone can point me in the right direction with this I would be extremely appreciative.
Thanks.
Return-Path is not the correct place for the VERP address, and will be ignored and/or overridden. You need to put it as the actual, honest to $dmr, real SMTP envelope sender (MAIL FROM:<>) address.
The question is a bit old, but hopefully my answer will contribute to someone who find this while googling.
I had the same problem, and the root cause is that you must use "MAIL FROM: " during the smtp exchange with the target server.
Setting the return-path in the MIME::Header gets overwriten by the smtp server itself precisely based on the MAIL FROM smtp command.
So you can have a Mail envelope containing From: root#somesite.net but make sure the smtp MAIL FROM uses $verp_email
For example, this is what I have done:
my $msg = MIME::Entity->build(
'Return-Path' => 'bounce+user=user-domain.com#my-server.com',
'From' => 'admin#my-server.com',
'To' => 'user#user-domain.com',
'Subject' => $subject,
'Errors-To' => 'bounce+user=user-domain.com#my-server.com'
);
## Then some more handling with MIME::Entity
## and finally send it over smtp
my #rcpt = $msg->smtpsend(
## Make it verbose for debugging
'Debug' => DEBUG,
'Hello' => 'mx1.my-server.com',
'Host' => 'mx.user-domain.com,
'MailFrom' => 'bounce+user=user-domain.com#my-server.com',
'To' => 'user#user-domain.com',
'Port' => 25,
);
I want to add multiple email address to a contact via SOAP api,
suppose i register a user from my php app. via registration page with testemail1#test.com for ex., so this will create a new contact in sugarcrm via set entry and "email1" parameter in soap set_entry call, in name_to_value_list array.
Now suppose i update the account information in my php web app. and updates email address to testemail2#test.com , so now, this should add this new email address to the current contact as primary email address and opt out the old email address (as we can add multiple email address to sing contact record).
see the sample code here :
$result = $mySoap->call('set_entry', array($session_id, 'module_name'=>'Contacts', array(
array("name" => 'first_name',"value" => $_POST['first_name']),
array("name" => 'last_name',"value" => $_POST['last_name']),
array("name" => 'email1',"value" => $_POST['email_address']), //Emails is suppose testemail1#test.com for first time
array("name" => 'primary_phone_c',"value" => $primary_phone),
array("name" => 'prefered_contact_c',"value" => $_POST['prefered_contact']),
array("name" => 'primary_address_street',"value" => $_POST['address']),
array("name" => 'primary_address_street_2_c',"value" => $_POST['address_2']),
array("name" => 'primary_address_city',"value" => $_POST['address_city']),
array("name" => 'primary_address_state',"value" => $_POST['address_state']),
array("name" => 'primary_address_postalcode',"value" => $_POST['address_postalcode']),
array("name" => 'address_country_c',"value" => $_POST['address_country']),
)));
So any sample Soap call or any idea like i use email2 field instead email1 in set_entry or else?
Thanks,
Dhaval Darji
I'm building a CakePHP website that sends an e-mail like this:
$email = new CakeEmail('default');
$email->template('test');
$email->emailFormat('html');
$email->to(array('john_doe#example.com' => 'John Doe'));
$email->subject('Test E-mail');
$email->helpers(array('Html', 'Text'));
$email->viewVars(
array(
...
)
);
if ($email->send()) {
$this->Session->setFlash('The e-mail was sent!', 'default', array('class' => 'alert alert-success'));
}
else {
$this->Session->setFlash('An unexpected error occurred while sending the e-mail.', 'default', array('class' => 'alert alert-error'));
}
I'd like to be able to capture the HTML rendered by the e-mail in a variable in addition to actually sending the e-mail. This way, I can record in the database the exact content of the e-mail's body. Is this doable?
Per line 50 of the MailTransport class, it appears the actual send() function returns the message and the header. So instead of:
if($email->send()) {
Try:
$mySend = $email->send();
if($mySend) {
//...
Then, $mySend should be an array:
array('headers' => $headers, 'message' => $message);
Thats what I do in my EmailLib:
https://github.com/dereuromark/tools/blob/2.0/Lib/EmailLib.php
it logs email attempts and captures the email output into a log file (email_trace.log) in /tmp/logs/ - if you are in debug mode it will only log (no emails sent - this has been proven quite useful for local delopment).
you can write a similar wrapper for your case.
but if you want to write it back into the DB Dave's approach seems to fit better.
I am facing an small issue regarding the Email Validation in my Zend Form.
My Code for the Email field is as
$emailId = new Zend_Form_Element_Text('email');
$emailId->setLabel("Email Adresse")
->addFilter('StripTags')
->addFilter('StringTrim')
->addValidator(new Validator_EmailValidator())
->addValidator('NotEmpty')
->addValidator(
'NotEmpty',
TRUE,
array('messages' => array(
'isEmpty' => 'Please enter your email id.'
)
)
);
Currently it is showing the Email Error Messages as :
What I want is to set a single error message in the place of all these errors and that is as :
"'abcd#shdsjah' is not a valid Email Id."
Since I am new to the Zend Framework, I don't have much idea about it, although I tried some code but they are useless.
Please help.....
Thanks In Advance....
When I was new to zend-framework, I faced this problem and got solution by using setErrors() method as:
//this will immediately call the method markAsError() which will show the error always
$emailId->setErrors(array('Please enter a valid Email Id.'));
You can also try :
//this will clearErrorMessages() and after that set the error messages
$emailId->setErrorMessages(array("Please enter a valid Email Id."));
Write this code after your code.
I hope it will be helpful to you......
Pass true as second argument of addValidator (breakChainOnFailure). The validation will stop at the first failure and you will have only have one error message.
I see that you are passing your own Custom Validator.
->addValidator(new Validator_EmailValidator())
You don't need to do that. Just use :
$validator = new Zend_Validate_EmailAddress()
Then just set that validator on the form item, and then set the messages against that validator.
So
$emailId->setValidator( $validator );
Now just set the Messages against the Validator, using the setMessages method.
These are all of the potential messages that you can change:
const INVALID = 'emailAddressInvalid';
const INVALID_FORMAT = 'emailAddressInvalidFormat';
const INVALID_HOSTNAME = 'emailAddressInvalidHostname';
const INVALID_MX_RECORD = 'emailAddressInvalidMxRecord';
const INVALID_SEGMENT = 'emailAddressInvalidSegment';
const DOT_ATOM = 'emailAddressDotAtom';
const QUOTED_STRING = 'emailAddressQuotedString';
const INVALID_LOCAL_PART = 'emailAddressInvalidLocalPart';
const LENGTH_EXCEEDED = 'emailAddressLengthExceeded';
Message Defaults
protected $_messageTemplates = array(
self::INVALID => "Invalid type given. String expected",
self::INVALID_FORMAT => "'%value%' is no valid email address in the basic format local-part#hostname",
self::INVALID_HOSTNAME => "'%hostname%' is no valid hostname for email address '%value%'",
self::INVALID_MX_RECORD => "'%hostname%' does not appear to have a valid MX record for the email address '%value%'",
self::INVALID_SEGMENT => "'%hostname%' is not in a routable network segment. The email address '%value%' should not be resolved from public network",
self::DOT_ATOM => "'%localPart%' can not be matched against dot-atom format",
self::QUOTED_STRING => "'%localPart%' can not be matched against quoted-string format",
self::INVALID_LOCAL_PART => "'%localPart%' is no valid local part for email address '%value%'",
self::LENGTH_EXCEEDED => "'%value%' exceeds the allowed length",
);
Now just change the messages to whatever you want. You will need to update every message.
$validator->setMessages(array(
Zend_Validate_EmailAddress::INVALID => "Invalid type given, value should be a string",
Zend_Validate_EmailAddress::INVALID_FORMAT => "'%value%' is no valid email address in the basic format local-part#hostname",
Zend_Validate_EmailAddress::INVALID_HOSTNAME => "'%hostname%' is no valid hostname for email address '%value%'",
Zend_Validate_EmailAddress::INVALID_MX_RECORD => "'%hostname%' does not appear to have a valid MX record for the email address '%value%'",
Zend_Validate_EmailAddress::INVALID_SEGMENT => "'%hostname%' is not in a routable network segment. The email address '%value%' should not be resolved from public network.",
Zend_Validate_EmailAddress::DOT_ATOM => "'%localPart%' can not be matched against dot-atom format",
Zend_Validate_EmailAddress::QUOTED_STRING => "'%localPart%' can not be matched against quoted-string format",
Zend_Validate_EmailAddress::INVALID_LOCAL_PART => "'%localPart%' is no valid local part for email address '%value%'",
Zend_Validate_EmailAddress::LENGTH_EXCEEDED => "'%value%' exceeds the allowed length",
));